request.headers

The incoming request headers as a lowercase-keyed object.

Since Fastify 5 Spec ↗

Syntax

request.headers

Returns

object — A map of header names (lowercased) to values.

Examples

import Fastify from 'fastify';

const app = Fastify();

app.get('/whoami', async (req) => {
  const auth = req.headers.authorization;
  return { authenticated: auth?.startsWith('Bearer ') ?? false };
});

Notes

Header names are always lowercase. Validate critical headers with a `headers` schema. Setting request.headers in an onRequest hook can rewrite incoming values before validation.