reply.header()

Sets a single response header.

Since Fastify 5 Spec ↗

Syntax

reply.header(name: string, value: string | number | string[])

Parameters

NameTypeRequiredDescription
name string No The header name.
value string | number | string[] No The header value.

Returns

FastifyReply — The reply, for chaining.

Examples

import Fastify from 'fastify';

const app = Fastify();

app.get('/download', async (_req, reply) => {
  reply
    .header('Content-Disposition', 'attachment; filename="data.txt"')
    .type('text/plain');
  return 'file body';
});

Notes

Headers must be set before send(). Use reply.headers() to set several at once. Calling header() again with the same name overwrites the value.