askrobots / dbbasic-examples
Public
Example DBBasic apps (an API, a blog and a microblog) and a template for new DBBasic modules.
danq9
Add official module template for creating DBBasic packages
17cf88a
1 year, 1 month ago
History
api.py · 1.0 KB · 27 lines
| 1 | from dbbasic_web.responses import json |
| 2 | import json as json_lib |
| 3 | |
| 4 | def handle(request): |
| 5 | """API documentation endpoint""" |
| 6 | docs = { |
| 7 | "name": "DBBasic Tasks API", |
| 8 | "version": "1.0", |
| 9 | "endpoints": { |
| 10 | "GET /": "API documentation", |
| 11 | "GET /health": "Health check", |
| 12 | "POST /auth/register": "Register new user", |
| 13 | "POST /auth/login": "Login and get token", |
| 14 | "POST /auth/logout": "Logout and invalidate token", |
| 15 | "GET /tasks": "List all tasks (supports ?status=done&search=foo&page=1&limit=20)", |
| 16 | "POST /tasks": "Create new task", |
| 17 | "GET /tasks/<id>": "Get task by ID", |
| 18 | "PUT /tasks/<id>": "Update task", |
| 19 | "DELETE /tasks/<id>": "Delete task" |
| 20 | }, |
| 21 | "authentication": { |
| 22 | "type": "Bearer token", |
| 23 | "header": "Authorization: Bearer <token>", |
| 24 | "obtain": "POST /auth/login with email and password" |
| 25 | } |
| 26 | } |
| 27 | return json(json_lib.dumps(docs, indent=2)) |