The URL Rewrite handler can be used to proxy and rewrite requests to a different API without writing any code. The handler allows mapping request data and parameters to a URL on another host. You can also combine the URL rewrite handler with policies such as the Change Method Inbound policy to modify virtually any aspect of your request.
Setup via Portal
The Rewrite Handler can be added to any route using the Route Designer. Open the Route Designer by navigating to the Code Editor tab then clicking routes.json. Inside of any route, select URL Rewrite from the Request Handlers drop down.
The following objects are available for substitution:
request: ZuploRequest- the full
params: Record<string, string>- The parameters of the route. For example,
params.productIdwould be the value of
:productIdin a route.
query: Record<string, string>- The query parameters of the route. For example,
query.filterBywould be the value of
headers: Headers- the incoming request's headers object
url: string- The full incoming request as a string
host: string- The
hostportion of the incoming url
hostname: string- The
hostnameportion of the incoming url
pathname: string- The
pathnameportion of the incoming url
port: string- The
portportion of the incoming url
searchportion of the incoming url
Use the following methods to encode portions of the URL:
encodeURIComponent()function encodes a URI by replacing each instance of certain characters with escape sequences.
e: An alias to
encodeURIComponentto help keep urls more readable. Can be used like
A few examples of the values of various substitutions.
Setup via Routes.json
The URL Rewrite handler can also be added manually to the routes.json file with the following route configuration.
"summary": "Proxy Welcome API",
"description": "This Route will proxy the welcome.zuplo.io api"