GuidesRequests

Forward requests

Proxy requests to upstream services using request.forward(). Use a trusted upstream URL: forwarding uses the runtime's default redirect handling, which can follow redirects.

Forward before consuming the body with request.body or request.original. Primate forwards the original stream without decoding it.

Simple proxy

Forward the original method and body stream.

// routes/api.ts
import route from "primate/route";

export default route({
  get(request) {
    return request.forward("https://api.example.com");
  },
});

Add headers

You can add headers to send along the forwarded request.

export default route({
  post(request) {
    return request.forward("https://api.example.com", { "X-Custom": "value" });
  },
});