app.put()
Registers a route handling HTTP PUT requests for full resource replacement.
Syntax
app.put(url, options?, handler) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
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.put<{ Params: { id: string }; Body: { name: string } }>(
'/cats/:id',
async (req) => {
return { id: req.params.id, name: req.body.name };
},
);
Notes
PUT should fully replace the resource and be idempotent. Validate both
params and body with a schema for safety.