reply.code()
Sets the HTTP status code for the response.
Syntax
reply.code(statusCode: number) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
statusCode | number | No | The HTTP status code to send. |
Returns
FastifyReply — The reply, for chaining.
Examples
import Fastify from 'fastify';
const app = Fastify();
app.post('/cats', async (req, reply) => {
reply.code(201);
return { created: true };
});
Notes
reply.code() and reply.status() are aliases. Set the code before send()
or before returning the payload in an async handler. The default is 200
(or 204 for an empty body).