Skip to content

6. Request rewriting

Evgeny Abramovich edited this page Dec 26, 2024 · 1 revision

Request rewriting

For each request you can rewrite the path, and the host. This is useful when you want to proxy a request to a different server, or when you want to change the path of the request.

To rewrite a request, you need to create a rewrites property in the mapping object. The rewrites property is an array of objects, each object containing the following properties:

mappings:
  - from: http://localhost:3000
    to: https://api.example.com
    rewrites:
      - from: /api
        to: /api/v1
        host: external-api.example.com
  • from - The path to match in the request. This can be a string or a string with wildcards.
  • to - The path to rewrite the request to. This can be a string or a string with wildcards.
  • host - The host to rewrite the request to. This is optional and can be used to rewrite the host of the request.

You can also use wildcards in from and to properties. For example:

mappings:
  - from: http://localhost:3000
    to: https://api.example.com
    rewrites:
      - from: /api/{resource}
        to: /api/v1/resource}/list

In this example, the {resource} wildcard is used to match part of the path. The value of the wildcard is passed to the to property, allowing you to rewrite the path dynamically.

Clone this wiki locally