Skip to content

API — Overview

The Neemias API is served by a Cloudflare Worker and organized by resource. All routes use the /api/v1 prefix and follow a declarative middleware pipeline that applies authentication, role-based authorization, rate limiting, and schema validation consistently.

Authentication and Headers

Every authenticated request must include three required headers:

HeaderValueRequired for
AuthorizationBearer <accessToken> (JWT HS256)All authenticated routes
X-Device-IdUUID v4 identifying the deviceAll authenticated routes
Idempotency-KeyUUID v4All mutations (POST, PATCH)

The Idempotency-Key ensures that operations retried due to timeout or network failure are not processed twice — essential for the offline-first architecture with asynchronous sync. See the Idempotency guide for ledger details.

Endpoint Summary (30+ routes)

Health & Meta

MethodRouteRolesDescription
GET/api/v1/healthPublicHealth check
GET/.well-known/security.txtPublicRFC 9116

Authentication

MethodRouteRolesDescription
POST/api/v1/auth/loginPublicLogin — rate limit: 5/min
POST/api/v1/auth/refreshPublicRenew token — rate limit: 10/min
POST/api/v1/auth/revokeAuthenticatedRevoke session
POST/api/v1/session/validateAuthenticatedValidate active session

Students

MethodRouteRolesDescription
GET/api/v1/studentsAuthenticatedList students (paginated, search)
POST/api/v1/studentsADMIN, CADASTROCreate student
PATCH/api/v1/students/:studentIdADMIN, CADASTROUpdate student
POST/api/v1/students/:studentId/deleteADMINSoft-delete with justification

Attendance

MethodRouteRolesDescription
POST/api/v1/attendance/eventsCHAMADOR, ADMINMark attendance

Classes

MethodRouteRolesDescription
GET/api/v1/classesAuthenticatedList classes
POST/api/v1/classesADMINCreate class
PATCH/api/v1/classes/:classIdADMINUpdate class
POST/api/v1/classes/:classId/deleteADMINSoft-delete class

Nuclei

MethodRouteRolesDescription
GET/api/v1/nucleiAuthenticatedList nuclei
POST/api/v1/nucleiADMINCreate nucleus
PATCH/api/v1/nuclei/:nucleusIdADMINUpdate nucleus
POST/api/v1/nuclei/:nucleusId/deleteADMINSoft-delete nucleus

Users

MethodRouteRolesDescription
GET/api/v1/usersADMINList users
POST/api/v1/usersADMINCreate user
PATCH/api/v1/users/:userIdADMINUpdate user
POST/api/v1/users/:userId/reset-passwordADMINReset password
POST/api/v1/users/:userId/deactivateADMINDeactivate user

Roles

MethodRouteRolesDescription
GET/api/v1/rolesADMINList roles
POST/api/v1/rolesADMINCreate custom role
PATCH/api/v1/roles/:roleNameADMINUpdate role
DELETE/api/v1/roles/:roleNameADMINDelete non-system role

Sync

MethodRouteRolesDescription
POST/api/v1/sync/eventsCHAMADOR, ADMIN, CADASTROBatch wrapper — multiple events
POST/api/v1/sync/eventAuthenticatedSingle atomic event via D1.batch()

Dev

MethodRouteRolesDescription
POST/_seedDemo data seed (dev only)

Middleware Pipeline

The route() helper (workers/src/middleware/pipeline.ts) builds each endpoint as a declarative middleware chain that executes in sequence. The typical flow is:

Request → rateLimit? → requireAuth (JWT) → requireRole → Zod validation → Handler → Response

Security headers (CORS, CSP, HSTS) are applied uniformly by the router. Errors follow the { error, message, details } envelope with canonical HTTP codes (401 UNAUTHORIZED, 403 FORBIDDEN_ROLE, 409 IDEMPOTENCY_KEY_REUSED_WITH_DIFFERENT_PAYLOAD, etc.).

See the API Guide for the complete workflow for implementing new routes and the OpenAPI specification for the detailed contract of each endpoint.

⚠️ Section under expansion.


Source: workers/src/router.ts + workers/CONTEXT.md

Distributed under MIT License.