Back to Templates
Route Custom Data
Use custom data from OpenAPI documents in policies and handlers.
Categories:
Programmability
Route Custom Data#
This sample demonstrates how to read custom data from a route configuration.
1/ Set Custom Data#
In the routes.oas.json
set a custom value inside of the route configuration as shown below. In this case, the x-custom
property is used, but any property that starts with x-
can be used.
{
"paths": {
"/custom-data": {
"post": {
"x-custom": {
"isSet": true,
"hello": "world"
}
}
}
}
}
2/ Read Custom Data#
From a handler or policy custom data can be read using ZuploContext
as shown below.
const data = context.route.raw<{ "x-custom": { hello: boolean } }>();
Recent Examples
API Linting
See how to use API linting to enforce api consistency and require Zuplo features like policies.
Backend for Frontend (BFF) Auth
Optimize UX and security in web applications with this approach.
Custom Rate Limiting
Invoke the Rate Limit policy programatically and then modify the 429 response.
Custom Modules
How to bundle custom node modules to use in your Zuplo project.