API Handler
In keiro
api handlers are functions exported from files under your routes directory,
we recommend using the helper defineHandler
for creating routes.
API Reference
API handlers take 2 arguments:
- RequestEvent: Contains the
request
,url
,params
,cookies
and requestlocals
. - Next: A function that call the next route, on api handlers the next route is always the
404
handler.
And must return a Response object.
Handlers can be defined in any of these ways:
-
Declaring a function.
-
Using the
defineHandler
helper. -
Using the
RequestHandler
type.
Catch-all methods
If you return a export default
function it will be called on any http method:
HTTP Method
You can return functions named: GET
, POST
, PUT
, PATCH
, DELETE
, HEAD
, OPTIONS
,
each will be called on that method.
The named methods have priority over the export default
, the rest will be handled by it.