All Projects → fastify → fastify-accepts

fastify / fastify-accepts

Licence: MIT license
Add accepts parser to fastify

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to fastify-accepts

fastify-caching
A Fastify plugin to facilitate working with cache headers
Stars: ✭ 123 (+141.18%)
Mutual labels:  fastify, fastify-plugin
fastify-autoroutes
fastest way to map directories to URLs in fastify
Stars: ✭ 70 (+37.25%)
Mutual labels:  fastify, fastify-plugin
fastify-csrf
A fastify csrf plugin.
Stars: ✭ 88 (+72.55%)
Mutual labels:  fastify, fastify-plugin
fastify-file-upload
Fastify plugin for uploading files
Stars: ✭ 68 (+33.33%)
Mutual labels:  fastify, fastify-plugin
fastify-passport
Use passport strategies for authentication within a fastify application
Stars: ✭ 150 (+194.12%)
Mutual labels:  fastify, fastify-plugin
fastify-axios
Add axios http client to your fastify instance
Stars: ✭ 28 (-45.1%)
Mutual labels:  fastify, fastify-plugin
fastify-webpack-hmr
Webpack hot module reloading for Fastify
Stars: ✭ 29 (-43.14%)
Mutual labels:  fastify, fastify-plugin
fastify-loader
The route loader for the cool kids!
Stars: ✭ 17 (-66.67%)
Mutual labels:  fastify, fastify-plugin
fastify-etag
Automatically generate etags for HTTP responses, for Fastify
Stars: ✭ 61 (+19.61%)
Mutual labels:  fastify, fastify-plugin
create-fastify-app
An utility that help you to generate or add plugin to your Fastify project
Stars: ✭ 53 (+3.92%)
Mutual labels:  fastify, fastify-plugin
fastify-hasura
A Fastify plugin to have fun with Hasura.
Stars: ✭ 30 (-41.18%)
Mutual labels:  fastify, fastify-plugin
fastify-openapi-glue
A plugin for Fastify to autogenerate a configuration based on a OpenApi(v2/v3) specification.
Stars: ✭ 94 (+84.31%)
Mutual labels:  fastify, fastify-plugin
fastify-env
Fastify plugin to check environment variables
Stars: ✭ 129 (+152.94%)
Mutual labels:  fastify, fastify-plugin
fastify-vite
This plugin lets you load a Vite client application and set it up for Server-Side Rendering (SSR) with Fastify.
Stars: ✭ 497 (+874.51%)
Mutual labels:  fastify, fastify-plugin
fastify-awilix
Dependency injection support for fastify
Stars: ✭ 52 (+1.96%)
Mutual labels:  fastify, fastify-plugin
fastify-leveldb
Plugin to share a common LevelDB connection across Fastify.
Stars: ✭ 19 (-62.75%)
Mutual labels:  fastify, fastify-plugin
fastify-postgres
Fastify PostgreSQL connection plugin
Stars: ✭ 144 (+182.35%)
Mutual labels:  fastify, fastify-plugin
fastify-vue
A nuxt.js fastify plugin
Stars: ✭ 27 (-47.06%)
Mutual labels:  fastify, fastify-plugin
session
Session plugin for fastify
Stars: ✭ 52 (+1.96%)
Mutual labels:  fastify, fastify-plugin
fastify-cors
Fastify CORS
Stars: ✭ 212 (+315.69%)
Mutual labels:  fastify, fastify-plugin

@fastify/accepts

CI NPM version js-standard-style

Add accepts parser to fastify

Install

npm i @fastify/accepts

Usage

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 for all available APIs.

This plugin adds to Request object all Accepts object methods.

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()
})

License

Licensed under MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].