Primate
Guides Requests

Read body

Access the request body by calling methods on request.body. Methods validate that the body is of the correct type.

Text -> string

Use text() to get the body as a string.

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

route.post(request => {
  const received = request.body.text();
  return { received };
});

JSON -> Record

Use json() to get the body as JSON (Record).

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

route.post(request => {
  const received = request.body.json();
  return { received };
});

Form -> Record

Use fields() to get the body as form (Record<string, string | File>).

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

route.post(request => {
  const received = request.body.fields();
  return { received };
});

Binary -> Blob

Use blods() to get the body as binary (Blob).

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

route.post(request => {
  const received = request.body.binary();
  return { received };
});