app.patch()

Registers a route handling HTTP PATCH requests for partial updates.

Since Fastify 5 Spec ↗

Syntax

app.patch(url, options?, handler)

Parameters

NameTypeRequiredDescription
url string No The route path.
options RouteShorthandOptions No Optional schema, hooks, and config.
handler Function No Async handler receiving (request, reply).

Returns

FastifyInstance — The instance, for chaining.

Examples

import Fastify from 'fastify';

const app = Fastify();

app.patch<{ Params: { id: string }; Body: Partial<{ name: string }> }>(
  '/cats/:id',
  async (req) => ({ id: req.params.id, ...req.body }),
);

Notes

Use a body schema where every property is optional to accept partial modifications. Return the updated representation or a 204 with no body.