reply.type()

Sets the Content-Type header of the response.

Since Fastify 5 Spec ↗

Syntax

reply.type(contentType: string)

Parameters

NameTypeRequiredDescription
contentType string No The MIME type to set.

Returns

FastifyReply — The reply, for chaining.

Examples

import Fastify from 'fastify';

const app = Fastify();

app.get('/feed', async (_req, reply) => {
  reply.type('application/xml');
  return '<rss version="2.0"></rss>';
});

Notes

A shortcut for reply.header('Content-Type', ...). Object payloads default to application/json; charset=utf-8, so this is mainly needed for non-JSON responses.