Principle:APIJSON APIJSON Demo REST API Routing
| Knowledge Sources | |
|---|---|
| Domains | API_Design, Web_Framework, Architecture |
| Last Updated | 2026-10-14 00:00 GMT |
Overview
Web routing pattern that maps HTTP POST requests to generic CRUD operations through a single controller, providing unified entry points for create, read, update, and delete operations driven by the JSON request body rather than URL structure.
Description
REST API Routing in APIJSON uses a single Spring @RestController with multiple @PostMapping endpoints that delegate to the APIJSON framework's APIJSONController base class. Rather than defining per-resource endpoints (e.g., /users/{id}, /comments/{id}), the controller exposes generic method-based endpoints (/get, /post, /put, /delete, /crud/{method}) that work with any table specified in the JSON body.
This solves:
- Endpoint explosion: Traditional REST requires N endpoints per resource; APIJSON needs only 7 generic endpoints for all resources.
- Method semantics: POST is used for all operations (to avoid URL encoding issues), with the actual CRUD method specified in the URL path or JSON body.
- Unified interface: Clients need only know the generic endpoint pattern, not table-specific routes.
The controller also provides:
- Tagged routes:
/get/{tag},/crud/{method}/{tag}for simplified per-resource access. - Router endpoint:
/router/{method}/{tag}for RESTful-style access with method and tag in URL. - CRUD-all endpoint:
/crudfor multi-operation requests in a single call.
Usage
Use this principle when:
- Building a generic API layer that works with any database table without per-resource endpoints.
- You want to minimize client-side HTTP method handling (all POST).
- You need both generic and tagged (per-resource) endpoint styles.
Theoretical Basis
Endpoint Mapping:
POST /get → DemoController.get() → super.get() → GET queries
POST /head → DemoController.head() → super.head() → HEAD (count)
POST /gets → DemoController.gets() → super.gets() → Secure GET
POST /heads → DemoController.heads() → super.heads() → Secure HEAD
POST /post → DemoController.post() → super.post() → INSERT
POST /put → DemoController.put() → super.put() → UPDATE
POST /delete → DemoController.delete() → super.delete() → DELETE
POST /crud → DemoController.crudAll() → multi-operation
POST /crud/{method} → DemoController.crud() → single method by path
POST /router/{m}/{t} → DemoController.router() → RESTful-style
POST /get/{tag} → DemoController.getByTag() → tagged query
POST /crud/{m}/{tag} → DemoController.crudByTag() → tagged CRUD
Delegation pattern:
@PostMapping(value = "get")
@Override
public String get(@RequestBody String request, HttpSession session) {
return super.get(request, session); // Delegates to APIJSONController<Long>
}
The controller uses @RequestBody String (not typed objects) to avoid URL encoding/decoding issues, letting the APIJSON parser handle JSON deserialization.
Related Pages
Implemented By
- Implementation:APIJSON_APIJSON_Demo_DemoController
- Implementation:APIJSON_APIJSON_Demo_DemoController_BigData
- Implementation:APIJSON_APIJSON_Demo_DemoController_Boot
- Implementation:APIJSON_APIJSON_Demo_DemoController_SimpleDemo
- Implementation:APIJSON_APIJSON_Demo_RepeatHeaderFilter
- Implementation:APIJSON_APIJSON_Demo_JSONRequest_JS