app.addContentTypeParser()
Registers a parser for a custom or raw request content type.
Syntax
app.addContentTypeParser(type, options, parser) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
type | string | RegExp | string[] | No | The content type(s) to handle. |
options | object | No | Options like { parseAs: "buffer" | "string" }. |
parser | Function | No | Function producing the parsed body. |
Returns
FastifyInstance — The instance, for chaining.
Examples
import Fastify from 'fastify';
const app = Fastify();
app.addContentTypeParser(
'application/csv',
{ parseAs: 'string' },
(_req, body, done) => {
done(null, String(body).trim().split('\n'));
},
);
Notes
Fastify ships JSON and url-encoded parsers. Use this to handle custom
media types or to capture the raw buffer (parseAs: 'buffer') for webhook
signature verification.