reply.headers()

Sets multiple response headers at once from an object.

Since Fastify 5 Spec ↗

Syntax

reply.headers(headers: Record<string, string | number>)

Parameters

NameTypeRequiredDescription
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.