Zuplo

Route Custom Data

Add custom metadata to routes and use it in your policies and handlers.

Route Custom Data

This sample demonstrates how to read custom data from a route configuration.

Use this example locally

To develop with this example locally, you can create a new Zuplo project using our CLI

Terminalbash
npx create-zuplo-api@latest my-api --example route-custom-data

Then, in the project directory run the following commands:

Terminalbash
npm install
npm run dev

Then complete the following setup steps:

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.

JSONjson
{
  "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.

TypeScriptts
const data = context.route.raw<{ "x-custom": { hello: boolean } }>();

Related Examples

Explore more examples in this category

Circuit Breaker

Programmability

Protect your backend from cascading failures by automatically blocking traffic when error rates exceed a threshold.

Custom Rate Limiting

Programmability

Customize the error response users see when they hit your API rate limits.

Custom Modules

Programmability

Use npm packages and third-party libraries in your Zuplo handlers and policies.

Dynamic Rate Limits

Programmability

Set different rate limits based on user subscription tier or API key metadata.