# @fastify/accepts

> Add accept parser to fastify

Latest version **5.0.6** (published 2026-09-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install @fastify/accepts
pnpm add @fastify/accepts
yarn add @fastify/accepts
bun add @fastify/accepts
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 5.0.6 |
| Published | 2026-09-10 |
| First published | 2022-04-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 22.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 80 |
| Author | allevo |
| Maintainers | matteo.collina, eomm, kibertoad, climba03003, gurgunday, tony133, metcoder95, fdawgs |

## Links

- npm: https://www.npmjs.com/package/@fastify/accepts
- Repository: https://github.com/fastify/fastify-accepts
- Homepage: https://github.com/fastify/fastify-accepts#readme
- Issues: https://github.com/fastify/fastify-accepts/issues
- Funding: https://github.com/sponsors/fastify
- npm.io page: https://npm.io/package/@fastify/accepts

## Dependencies (2)

- [accepts](https://npm.io/package/accepts.md) ^1.3.8
- [fastify-plugin](https://npm.io/package/fastify-plugin.md) ^6.0.0

## Recent versions

- 5.0.6 (latest) — 2026-09-10
- 5.0.0 (next) — 2024-09-04
- 5.0.5 — 2026-09-04
- 5.0.4 — 2025-12-01
- 5.0.3 — 2025-09-28
- 5.0.2 — 2024-12-04
- 5.0.1 — 2024-09-21
- 5.0.0-pre.fv5.2 — 2024-08-07
- 5.0.0-pre.fv5.1 — 2024-06-29
- 4.3.0 — 2023-12-03
- 4.2.0 — 2023-06-10
- 4.1.0 — 2022-11-24
- 4.0.1 — 2022-08-26
- 4.0.0 — 2022-05-13
- 3.0.0 — 2022-04-27

## README

# @fastify/accepts

[![CI](https://github.com/fastify/fastify-accepts/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/fastify-accepts/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/@fastify/accepts.svg?style=flat)](https://www.npmjs.com/package/@fastify/accepts)
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)

Add an accepts parser to Fastify.

## Install

`npm i @fastify/accepts`

### Compatibility

| Plugin version | Fastify version |
| ---------------|-----------------|
| `>=5.x`        | `^5.x`          |
| `^4.x`         | `^4.x`          |
| `>=2.x <4.x`   | `^3.x`          |
| `^1.x`         | `^2.x`          |
| `^1.x`         | `^1.x`          |


Please note that if a Fastify version is out of support, then so are the corresponding versions of this plugin
in the table above.
See [Fastify's LTS policy](https://github.com/fastify/fastify/blob/main/docs/Reference/LTS.md) for more details.

## Usage

```js
const fastify = require('fastify')
const Boom = require('@hapi/boom')

fastify.register(require('@fastify/accepts'))

fastify.post('/', function (req, reply) {
  const accept = req.accepts() // Accepts object
  switch(accept.type(['json', 'html'])) {
    case 'json':
      reply.type('application/json').send({hello: 'world'})
      break
    case 'html':
      reply.type('text/html').send('<b>hello, world!</b>')
      break
    default:
      reply.send(Boom.notAcceptable('unacceptable'))
      break
  }
})
```

See [accepts package](https://www.npmjs.com/package/accepts) for all available APIs.

This plugin adds to `Request` object all `Accepts` object methods.

```js
fastify.post('/', function (req, reply) {
  req.charset(['utf-8'])
  req.charsets()
  req.encoding(['gzip', 'compress'])
  req.encodings()
  req.language(['es', 'en'])
  req.languages()
  req.type(['image/png', 'image/tiff'])
  req.types()
})
```

### Options

- `decorateReply` If `true`, the `Reply` object will be decorated with the `requestAccepts`, `requestTypes`, `requestCharsets`, `requestEncodings`, and `requestLanguages` methods, which will return the corresponding values from the `Request` object. Default: `false`.

## License

Licensed under [MIT](./LICENSE).

---
_Source: https://npm.io/package/@fastify/accepts · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
