Routes
You can add a route to your app using any of the following methods:
App#get: Add a GET route handler.App#post: Add a POST route handler.App#put: Add a PUT route handler.App#delete: Add a DELETE route handler.App#method: Add a route handler for a custom method.App#any: Add a route handler for any method at a given path.
"/api/users", ,
"/api/users", ,
"/api/users/:id", ,
"/api/users/:id", ,
"PATCH", "/api/users/:id", ,
"/api/users", , ;
Arguments:
route – The path to match against.definition – Define parameters and OpenAPI docs about the route.handler – The callback function executed when a matching request is received.Document the route using the second argument. This is where all the OpenAPI docs are defined, and where you define the input/output schemas for the route.
;
All available properties are typed, so your editor can tell you what's available.
The handler function receives "context" as its first argument. This object contains information about the request:
route – The matched routepath – The full URL pathnameparams – The parsed path parametersquery – The parsed query parametersbody – The parsed request bodyrequest – The original Request instanceurl – The parsed URLset – Util for setting response headersstatus – Util for setting the response statusYou can add objects, variables, or functions to the request context via hooks.
For simple objects, Zeta provides the decorate function:
;
// or .decorate("db", db);
"/example", ,
decorate is shorthand for returning a value from the onTransform hook:
;
"/example", ,