request.body

The parsed request payload for methods that carry a body.

Since Fastify 5 Spec ↗

Syntax

request.body

Returns

any — The parsed body, shaped by the body schema.

Examples

import Fastify from 'fastify';

const app = Fastify();

app.post<{ Body: { name: string } }>(
  '/cats',
  {
    schema: {
      body: {
        type: 'object',
        required: ['name'],
        properties: { name: { type: 'string', minLength: 1 } },
      },
    },
  },
  async (req) => ({ created: req.body.name }),
);

Notes

The body is parsed by the matching content-type parser. Define a `body` schema so malformed payloads are rejected with a 400 before the handler.