Publishing APIs

Transformations

Rewrite requests and responses at the gateway without changing your server.

Transformations change requests on their way to your server, and responses on their way back, at the gateway. You don't have to change your code. Common uses: adding a private auth header, renaming a parameter, moving an API to a new path, or hiding a field.

Request and response rules

Open Transformations and add a rule to either list:

  • Request transformations run before the request is forwarded to you.
  • Response transformations run before the response is returned to the consumer.

Rules run in order, top to bottom.

What a rule does

Each rule has an action:

ActionEffect
AddAdd a header, query parameter, body property (and so on) with a value you choose.
RemoveRemove a header, parameter or property.
RemapMove a value from one place to another, or rename it.

The value for Add can be static (a fixed value), a variable (taken from another part of the request), or a template combining several values with Mustache syntax, such as {{request.query.city}}. For values that might already exist, choose whether to overwrite if exists or ignore if exists.

Scope

Each rule applies to all endpoints or only the ones you select, and to all plans or only the ones you select. That lets you do things like expose extra response fields only on paid plans.

Examples

The Examples button shows ready-made rules you can adapt, including:

  • Add a private auth header to every request forwarded upstream, across all endpoints and plans. API consumers never see it.
  • Remap the original request path /v1/users/{userId} to a new upstream path /v2/accounts/{userId}, for one endpoint.
  • Remap the original POST method to GET before the request is forwarded, for one endpoint.
  • Remap a query parameter into a nested city property inside a filters object on the request body.
  • Remove a form parameter from requests to one endpoint, on the Basic plan only.
  • Remap a response body property into a response header, for one endpoint, on paid plans only.
  • Add a fixed or templated body property on every request (JSON requests only).

Tips

  • Test with the playground after adding a rule: the Request view in the results shows what was sent.
  • Keep rules simple. If you need heavy logic, it usually belongs in your API.

Something unclear or missing? Email [email protected].