Coder Social home page Coder Social logo

fastify-accepts's Introduction

@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

fastify-accepts's People

Contributors

a-a-github-a-a avatar allevo avatar delvedor avatar dependabot-preview[bot] avatar dependabot[bot] avatar dimonnwc3 avatar eomm avatar fdawgs avatar frikille avatar github-actions[bot] avatar greenkeeper[bot] avatar jsumners avatar lependu avatar mcollina avatar optic-release-automation[bot] avatar salmanm avatar samchungy avatar serayaeryn avatar uzlopak avatar zekth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fastify-accepts's Issues

Expose accepts() methods in the Request

I think having some more accessors in the Request  might be pretty handy, as an example:

fastify.post('/', function (req, reply) {
  switch(req.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
  }
})

Minimum requested version

The minimum requested version of Fastify for this plugin is v0.25.0, why?
Since you are just using decorateRequest you can use v0.13.1 :)

An in-range update of request is breaking the build 🚨

Version 2.82.0 of request just got published.

Branch Build failing 🚨
Dependency request
Current Version 2.81.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As request is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪

Status Details
  • coverage/coveralls Coverage pending from Coveralls.io Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

Commits

The new version differs by 27 commits.

  • 0ab5c36 2.82.0
  • ffdf0d3 Updating deps.
  • 4386836 Merge branch 'master' of github.com:request/request
  • 1527407 Merge pull request #2703 from ryysud/add-nodejs-v8-to-travis
  • 3afcbf8 Merge branch 'master' of github.com:request/request
  • 479143d Update of hawk and qs to latest version (#2751)
  • 169be11 Add Node.js v8 to Travis CI
  • 643c43a Fixed some text in README.md (#2658)
  • e8fca51 chore(package): update aws-sign2 to version 0.7.0 (#2635)
  • e999203 Update README to simplify & update convenience methods (#2641)
  • 6f286c8 lint fix, PR from pre-standard was merged with passing tests
  • a765593 Add convenience method for HTTP OPTIONS (#2541)
  • 52d6945 Add promise support section to README (#2605)
  • b12a624 refactor(lint): replace eslint with standard (#2579)
  • 29a0b17 Merge pull request #2598 from request/greenkeeper-codecov-2.0.2

There are 27 commits in total.

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Accept type defaults to first item

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

2.1.0

Plugin version

No response

Node.js version

16.13.1

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

12.1

Description

When NO Accept: header is specified in the HTTP request,

req.accepts().type(a, b)

returns a by default whereas it should return null or undefined in such a case.

Steps to Reproduce

Issue a query with no Accept: header, and ask for a value in a type array.

Expected Behavior

return null when no Accept header match an array value
return undefined when no Accept header has been found.

ChainAlert: npm package release (2.3.0) has no matching tag in this repo

Dear fastify-accepts maintainers,
Thank you for your contribution to the open-source community.

This issue was automatically created to inform you a new version (2.3.0) of fastify-accepts was published without a matching tag in this repo.

As part of our efforts to fight software supply chain attacks, we would like to verify this release is known and intended, and not a result of an unauthorized activity.

If you find this behavior legitimate, kindly close and ignore this issue. Read more

badge

An in-range update of accepts is breaking the build 🚨

The dependency accepts was updated from 1.3.5 to 1.3.6.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

accepts is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for 1.3.6
  • deps: mime-types@~2.1.24
    • deps: mime-db@~1.40.0
Commits

The new version differs by 47 commits.

There are 47 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml
  • The new Node.js version is in-range for the engines in 1 of your package.json files, so that was left alone

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of fastify-plugin is breaking the build 🚨

Version 1.2.0 of fastify-plugin was just published.

Branch Build failing 🚨
Dependency fastify-plugin
Current Version 1.1.3
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

fastify-plugin is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details
  • coverage/coveralls First build on greenkeeper/fastify-plugin-1.2.0 at 95.0% Details

Release Notes v1.2.0
  • use fp meta name option instead of new symbol #44
Commits

The new version differs by 3 commits.

  • 9e164ab Bumped v1.2.0.
  • cdac717 chore(package): update ts-node to version 7.0.0 (#43)
  • 60832a3 have fp use meta name option instead of new symbol (#44)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of fastify is breaking the build 🚨

Version 1.8.0 of fastify was just published.

Branch Build failing 🚨
Dependency fastify
Current Version 1.7.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

fastify is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

Release Notes v1.8.0

Features

  • Configure request id header key - #1024
  • Support case insensitivity. - #1017
  • Feature/#713 beforeHandler for setNotFoundHandler - #1005

Fixes

Docs

  • Update Ecosystem.md - #874
  • add-chinese-doc-link - #1021
  • Update Middlewares.md - #996
  • Rename swaggergen to openapi glue - #1013
  • Update Reply.md - #1003
  • Add fastify-wamp-router plugin to docs/Ecosystem.md - #1002
  • Add missing documentation links - #1001
  • fix syntax in doc - #997
  • Add fastify-xml-body-parser in community list - #782

Typescript

  • fix listen ts types - #1000

Internals

  • test: add test case for request.id - #1030
  • Add test for checking multipart request using form-data module - #1026
  • Resolves issue #1006 - #1008
Commits

The new version differs by 19 commits.

  • 55fc867 Bumped v1.8.0
  • e58c627 test: add test case for request.id (#1030)
  • 7f734fd Add test for checking multipart request using form-data module (#1026)
  • 4949a9c Configure request id header key (#1024)
  • 7476cb4 Update Ecosystem.md (#874)
  • 42d10f6 New instructions have been added for use with fastif-cli (#1020)
  • a137087 add-chinese-doc-link (#1021)
  • 92ee7db Support case insensitivity. (#1017)
  • 0dfb356 Update Middlewares.md (#996)
  • 8955f27 Resolves issue #1006 (#1008)
  • dd337fd Feature/#713 beforeHandler for setNotFoundHandler (#1005)
  • 1b92295 Rename swaggergen to openapi glue (#1013)
  • 2f96a80 fix listen ts types (#1000)
  • 68114ee Add fastify-wamp-router plugin to docs/Ecosystem.md (#1002)
  • 724199f Update Reply.md (#1003)

There are 19 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Typescript Build Error on Accepts

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

Hey there,

Not sure whether this should be raised as a bug or not but when trying to install this in a TS project as this may be intended but I received the following error:

https://github.com/seek-oss/slowify/actions/runs/5167692569/jobs/9308739911

Error: tsc      │ node_modules/@fastify/accepts/types/index.d.ts(1,25): error TS7016: Could not find a declaration file for module 'accepts'. '/home/runner/work/slowify/slowify/node_modules/accepts/index.js' implicitly has an 'any' type.

Could @types/accepts be made a dependency for this library to avoid consumers needing to install it themselves?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.