Service routes and the request lifecycle
Map a route declaration to HTTP, then follow middleware, validation, business logic, and error reporting.
Define a route as a method plus audience, module, and action. For example, GET public.config.get maps to GET /_/public/config/get. The same handler can run in-process, where matching uses the full name and exact method.
Map a route name to an address
The existing configuration read route illustrates the convention:
defineRouteModule("config", {
routes: [defineRoute("GET public.config.get", { handler: getConfig })],
});
GET is the method, public the audience, config the module, and get the action. On the public site this maps to GET /_/public/config/get. Dotted module keys can have multiple segments. Service routes use query parameters, request bodies, or files for dynamic inputs.
Follow a call through the runtime
- The registry locates the module and loads its routes on demand.
- Registered middleware establishes request context and performs the applicable access and authentication checks.
- The handler reads the query, body, or files, validates them using the declared schema, then calls a use case.
- Service returns the result. JSON HTTP responses carry data or an error and include a request ID for diagnosis.
In-process calls reuse route declarations and middleware. They match the exact method and route name. HTTP can use the applicable ANY fallback and prefers GET for HEAD.
Use error codes to locate the failure
A 404 with route_not_found means the request did not match a Service route. A 404 with config_not_found means the config controller ran but did not return a publicly readable record. Check error.code and meta.requestId before tracing registration, input, or business data.
| Response | What to check |
|---|---|
404 · route_not_found |
Service Origin, audience, module, and action |
405 · method_not_allowed |
Compare the request method with the allowed methods in the error details |
400 · invalid_input |
Check whether the parameter belongs in query, body, or files, and inspect the failing field |
404 · config_not_found |
Check the test key and whether the config record is public |
Follow the public config route in controllers, validation, and responses.
Find the relevant source
| Question | Starting point |
|---|---|
| How is the module registered and loaded? | packages/service/app/route-modules.ts |
| Which context owns an operation? | The context’s route.ts |
| Which input failed validation? | The handler’s validator and its query/body/files source |
| Which use case should another context call? | The owning context’s root service.ts |
When debugging an HTTP call, record the method, address, status, and request ID. For management authentication and response shapes, see the technical reference.