reply.headers()
Sets multiple response headers at once from an object.
Syntax
reply.headers(headers: Record<string, string | number>) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
headers | object | No | A map of header names to values. |
Returns
FastifyReply — The reply, for chaining.
Examples
import Fastify from 'fastify';
const app = Fastify();
app.get('/secure', async (_req, reply) => {
reply.headers({
'X-Frame-Options': 'DENY',
'X-Content-Type-Options': 'nosniff',
});
return { ok: true };
});
Notes
A convenient batch form of reply.header(). For broad security headers
across all routes, prefer @fastify/helmet instead of setting them per
handler.