Simplifying Backend CRUD with APIJSON: One Interface per Operation
This article explains how APIJSON can replace dozens of traditional SpringBoot controller methods with a single configurable endpoint, demonstrating concise request formats, permission annotations, and example code for creating, reading, updating, deleting, and aggregating data in a Java backend.
Traditional SpringBoot development often requires multiple controller methods for each CRUD operation, leading to verbose code and duplicated configuration; even a simple endpoint can take three lines of code, and a full set of operations may exceed twenty‑four lines.
APIJSON solves this problem by allowing a single HTTP endpoint to handle all CRUD actions based on the request method (GET, POST, PUT, DELETE, HEAD) and a concise JSON request body, eliminating the need to write separate controller methods.
Example of a minimal SpringBoot controller method:
@RequestMapping("test/{request}")
public String test(@PathVariable String request) {
return request + ": Hello World";
}Using APIJSON, the same functionality can be achieved with just a few lines of configuration and a JSON request. For a simple GET request to retrieve a user:
base_url/get/To retrieve a list of users:
base_url/get/To retrieve comments and comment lists:
base_url/get/comment
base_url/get/comment/listAll these operations share the same GET endpoint, distinguished only by the URL path.
Creating a new record uses the POST endpoint:
{
"Comment": {
"userId": 82001,
"momentId": 15,
"content": "测试新增评论"
},
"tag": "Comment"
}Deleting a record uses the DELETE endpoint:
{
"Comment": {"id": 1510394480987},
"tag": "Comment"
}Batch deletion can be performed by providing an array of IDs:
{
"Comment": {"id{}": [1510394480987, 1510394804925]},
"tag": "Comment[]"
}Updating a record uses the PUT endpoint, and batch updates are similar, using an array of IDs and the fields to modify.
{
"Comment": {"id": 22, "content": "测试修改评论"},
"tag": "Comment"
}Aggregations and statistics are handled with the HEAD endpoint, for example to count comments containing a keyword:
{
"Comment": {"content$": "%测试%"}
}Permission control is managed with a simple three‑line annotation on the model class:
@MethodAccess
public class User { }By configuring role permissions (e.g., allowing only UNKNOWN and ADMIN roles to POST), APIJSON enforces security without additional code.
Overall, APIJSON reduces the amount of boilerplate code dramatically, allowing developers to define data models and permission rules once, then perform any CRUD or aggregation operation through a unified JSON API.
Architecture Digest
Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.
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.