Accelerate Java API Development with magic-api: A Hands‑On Guide
Discover how magic‑api, a Java‑based rapid API framework, streamlines backend development by eliminating boilerplate code, enabling visual API design, dynamic configuration, and seamless database integration, all demonstrated through a step‑by‑step tutorial using a SpringBoot e‑commerce project.
Why Use magic-api?
When a new project requires fully dynamic page configuration—such as dropdown options, internationalization, and other simple conditions—all front‑end settings must be returned via API. With a tight schedule of only ten days and no extra staff, the author turned to magic‑api, a Java‑based rapid API development framework, to dramatically reduce development effort.
What Is magic-api?
magic‑api automatically maps UI‑defined endpoints to HTTP APIs, removing the need to write
Controller,
Service,
Dao,
Mapper,
XML,
VOand other Java objects. The UI lets you configure request paths, methods, parameters, and return values visually.
Recommended project: a SpringBoot + Vue + uni‑app e‑commerce system (GitHub ★60K) that includes both front‑end mall and back‑end admin modules. Project address: https://github.com/macrozheng/mall Video tutorials: https://www.macrozheng.com/video/
Environment Setup
Add the core package to
pom.xml:
<code><dependency>
<groupId>org.ssssssss</groupId>
<artifactId>magic-api-spring-boot-starter</artifactId>
<version>0.7.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency></code>Configure
application.yml(database settings are optional):
<code>magic-api:
web: /magic/web # UI address
server:
port: 9999
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://47.93.6.5:3306/magic-api
username: root
password: xinzhifu521</code>Environment is ready.
Practical Demo
Open the visual UI at
http://127.0.0.1:9999/magic/weband create a group whose prefix acts like
@Controller("/order"). Then add an endpoint
order_detailthat simply returns static data:
<code>return ‘小富最帅’</code>Accessing
http://127.0.0.1:9999/order/order_detailreturns the string. You can also return JSON directly.
For path variables, define the URL as
/order_detail/{id}and use the
requestmodule to obtain the parameter:
<code>import request;
a = path.id</code>Even without writing a single Java class, a functional API is created.
magic‑api also supports database operations via a Python‑like scripting module. By importing
dband executing SQL, the result is returned as JSON, eliminating many intermediate steps.
Its syntax is close to Java but more concise; loops and lambdas can be written as:
<code>var sum = 0;
var list = [1,2,3,4,5];
for(val in list){
sum = sum + val;
}
list.each(it => sum+= it + 1)</code>Advanced features include calling Java APIs, integrating Redis, MongoDB, and many ready‑made demos.
Repository: https://gitee.com/ssssssss-team/magic-api
Personal Experience
During a rushed development cycle, magic‑api saved more than half of the backend coding time and greatly facilitated front‑end integration. By defining data structures early, the front‑end could test against real endpoints while the back‑end later replaced static data with business logic.
However, the author advises using magic‑api only for simple, configuration‑driven interfaces; core business logic should still follow proper architectural rules to ensure stability and security.
Further Resources
GitHub ★60K e‑commerce tutorial (SpringBoot 2.7, ~40 hours, 100 lessons)
Video tutorials and full project architecture are linked throughout the article.
macrozheng
Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.