1. Examples
  2. Rewrite Request Body

Rewrite Request Body

Transform request bodies before forwarding to your backend API.

Deploy to Zuplo
Deploy to Zuplo

Prerequisite: You need a Zuplo account to run this example. Sign up for free

This sample demonstrates how to rewrite the body of an incoming JSON request.

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 rewrite-request-body

Then, in the project directory run the following commands:

Terminalbash
npm install
npm run dev

Then complete the following setup steps:

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.

TypeScriptts
// Read the incoming body
const body = await request.json();

// Create a new body with additional properties
const outbound = {
  ...body,
  id: crypto.randomUUID(),
  createdOn: new Date(),
};

// Return a new request with the modified body
return new Request(request, {
  body: JSON.stringify(outbound),
});

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

Terminalbash
curl -X POST https://API_URL/rewrite-body
   -H "Content-Type: application/json"
   -H "Authorization: user123"
   -d '{"hello": "world" }'

Response:

JSONjson
{
  "url": "https://echo.zuplo.io/rewrite-body",
  "method": "POST",
  "query": {},
  "body": {
    "hello": "world",
    "id": "d06b3a27-b40e-48f2-934a-1585ab993e8a",
    "createdOn": "2023-06-05T15:46:14.202Z"
  },
  ...
}

Quick Links

View on GitHubDocumentation

Run Locally

Clone and run this example:

npx create-zuplo-api --example rewrite-request-body

On This Page

Related Examples

Explore more examples in this category

Idempotency Keys

Programmability

Prevent duplicate API requests and ensure safe retries for payments and critical operations.

View Example

Custom Rate Limiting

Programmability

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

View Example

Custom Modules

Programmability

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

View Example

Dynamic Rate Limits

Programmability

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

View Example
Check all of our Examples

Scale your APIs with
confidence.

Start for free or book a demo with our team.
Book a demoStart for Free
SOC 2 TYPE 2High Performer Spring 2025Momentum Leader Spring 2025Best Estimated ROI Spring 2025Easiest To Use Spring 2025Fastest Implementation Spring 2025

Get Updates From Zuplo

Zuplo logo
© 2026 zuplo. All rights reserved.
Products & Features
API ManagementAI GatewayMCP ServersMCP GatewayDeveloper PortalRate LimitingOpenAPI NativeGitOpsProgrammableAPI Key ManagementMulti-cloudAPI GovernanceMonetizationSelf-Serve DevX
Developers
DocumentationBlogLearning CenterCommunityChangelogIntegrations
Product
PricingSupportSign InCustomer Stories
Company
About UsMedia KitCareersStatusTrust & Compliance
Privacy PolicySecurity PoliciesTerms of ServiceTrust & Compliance
Docs
Pricing
Sign Up
Login
ContactBook a demoFAQ
Zuplo logo
DocsPricingSign Up
Login