REST API Example
A REST API example with CRUD operations, authenticated endpoints, and multiple route patterns.
Source: examples/rest-api/
Key Concepts Demonstrated
Section titled “Key Concepts Demonstrated”- Authenticated endpoints — scopes enforce access control
- Public + private routes — health check is public, CRUD requires auth
- Dynamic segments —
[id]in route paths - Multiple HTTP methods — GET, POST, PUT, DELETE
- Auto status codes — POST → 201, DELETE → 204
Endpoints
Section titled “Endpoints”| Route | Auth | Description |
|---|---|---|
GET /health | Public | Health check |
GET /tasks | tasks.read | List tasks |
POST /tasks | tasks.write | Create task (201) |
GET /tasks/{id} | tasks.read | Get task by ID |
PUT /tasks/{id} | tasks.write | Update task |
DELETE /tasks/{id} | tasks.write | Delete task (204) |
Run It
Section titled “Run It”cd examples/rest-apinpm installvk dev# Publiccurl http://localhost:3000/health
# Authenticated (requires Bearer token with tasks.read scope)curl -H "Authorization: Bearer <token>" http://localhost:3000/tasks
# Createcurl -X POST -H "Authorization: Bearer <token>" \ -H "Content-Type: application/json" \ -d '{"title": "New task"}' \ http://localhost:3000/tasks