Rewrite Request Body
Use a custom policy to rewrite the body of a Request
Rewrite Request Body#
This sample demonstrates how to rewrite the body of an incoming JSON request.
1/ Create Route#
Create a route that uses the URL Rewrite Handler. The rewrite points to the Zuplo Echo API at https://echo.zuplo.io.
2/ Add Policy#
Create a custom policy. This policy just takes body of the incoming request and adds two properties to the object.
Create an empty incoming policy called rewrite-body.ts
and add the following code to the function.
3/ Call the API#
The API can now be called and will return the echoed response. Note, the echo API returns a serialized version of the entire request so you will get back the body, url, headers, etc. In this example, you will see that the body has the original hello
property and two new properties id
and createdOn
Response: