RequestRocketRequestRocketDocs
Control

Request transforms

Run code after overrides and before the target call.

A request transform is a default-exported function. It runs after overrides and before RequestRocket calls the target. transformType is request. Attach one to a proxy or a direct MCP server. Path, header, query, body, and token matches are on Predicates.

The function receives (proxyContext, proxyRequest). Return a request-shaped object. RequestRocket accepts method, a relative url, headers, params, and data from that object. The target base URL and target credential are not exposed to the transform.

Add a request transform

Open a saved proxy, open the Control tab, and expand Request Transforms. The code editor is the function RequestRocket runs.

Saved proxy, Control tab, Request Transforms section expanded, with the code editor visible

Rename a body field

This example renames customer_name to customerName. Request bodies are sent only for POST, PUT, and PATCH calls.

export default function transform(proxyContext, proxyRequest) {
  const { customer_name, ...rest } = proxyRequest.data ?? {};

  return {
    ...proxyRequest,
    data: {
      ...rest,
      customerName: customer_name,
    },
  };
}

Add a computed header

export default function transform(proxyContext, proxyRequest) {
  return {
    ...proxyRequest,
    headers: {
      ...proxyRequest.headers,
      "x-request-path": proxyContext.path,
    },
  };
}

Test the transform

Save the transform, then send one call through the proxy. Use Request logs to find the call and confirm the target received the transformed request.

Runtime rules

  • The source must default-export a function.
  • Imports, require, fetch, and process are rejected.
  • The sandbox has no network or filesystem access. It has a five-second execution limit and a 32 MB memory limit.
  • A returned url must be a relative target path. A transform cannot change the target origin.
  • Only the highest-priority applicable request transform runs.

Next

On this page