HTTP & middleware

The Moonlight API uses one versioned URL, but Pionia still speaks real HTTP — status codes, headers, and middleware chains matter for production apps like DeskFlow.

Guide map

TopicPage
Envelopes & status codesRequests & responses
Working with JSON payloadsCollections
Global request pipelineMiddleware
Errors & validationExceptions
Static routes & SPA fallbackHTTP routing

DeskFlow example

When Alex creates a task without a title, DeskFlow returns HTTP 422 with returnCode in the JSON body — see Validation and Exceptions.

Add RequestIdMiddleware so support tickets reference a single request ID — covered in Middleware.

Suggested order

  1. Requests & responses — envelopes first
  2. Collections — read JSON in actions
  3. Exceptions — 422 when title is missing
  4. Middleware — request IDs for support
  5. HTTP routing — static files and SPA fallback
Building your API

Services that produce these responses.

Security

Auth runs after middleware.

Common mistakes

  • Debugging in actions before reading envelopes — start with Requests & responses so status codes make sense.
  • Adding middleware for auth — authentication backends run after middleware; use mustAuthenticate() on services.
  • Expecting RESTful paths per action — Moonlight uses POST /api/v1/ with a JSON body, not /api/v1/task/list.