Implementation:APIJSON APIJSON Demo DemoController SimpleDemo
| Knowledge Sources | |
|---|---|
| Domains | Web_Framework, API_Design, Authentication |
| Last Updated | 2026-10-14 00:00 GMT |
Overview
Concrete tool for routing HTTP requests to CRUD operations with full login/logout authentication implementation in the APIJSON SimpleDemo Spring Boot 3 variant.
Description
The DemoController class (SimpleDemo variant) extends APIJSONController<Long> and provides CRUD endpoints plus a complete login implementation that validates username/password, looks up the Privacy model, verifies credentials via HEADS requests, and stores session state. It also implements logout with session invalidation and user ID extraction. Uses jakarta.servlet (Spring Boot 3).
Usage
Use this controller when deploying the APIJSON SimpleDemo Spring Boot 3 server with authentication.
Code Reference
Source Location
- Repository: APIJSON_APIJSON_Demo
- File: APIJSON-Java-Server/APIJSONSimpleDemo-SpringBoot3/src/main/java/com/example/apijsondemo/controller/DemoController.java
- Lines: 1-252
Signature
@RestController
public class DemoController extends APIJSONController<Long> {
@Override
public Parser<Long> newParser(HttpSession session, RequestMethod method);
@PostMapping("{method}")
@Override
public String crud(@PathVariable String method, @RequestBody String request, HttpSession session);
@PostMapping("{method}/{tag}")
@Override
public String crudByTag(@PathVariable String method, @PathVariable String tag,
@RequestParam Map<String, String> params, @RequestBody String request, HttpSession session);
@PostMapping("login")
public JSONObject login(@RequestBody String request, HttpSession session);
@PostMapping("logout")
@Override
public JSONObject logout(HttpSession session);
}
Import
import com.example.apijsondemo.controller.DemoController;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| request | String | Yes | JSON request body |
| session | HttpSession | Yes | HTTP session for auth state |
Outputs
| Name | Type | Description |
|---|---|---|
| login() returns | JSONObject | Auth result with user ID and session state |
| logout() returns | JSONObject | Logout success response |
| crud() returns | String | JSON response from APIJSON parser |
Usage Examples
Login Flow
# Login request
curl -X POST http://localhost:8080/login \
-H "Content-Type: application/json" \
-d '{"username":"test","password":"123456"}'
# Response: { "code": 200, "Privacy": { "id": 82001, ... } }