Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Generated on Apr 23, 2024 via pnpm

accepts 1.3.8

Higher-level content negotiation
Package summary
Share
0
issues
1
license
4
MIT
Package created
27 Dec 2013
Version published
2 Feb 2022
Maintainers
1
Total deps
4
Direct deps
2
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
4 Packages, Including:
accepts@1.3.8
mime-db@1.52.0
mime-types@2.1.35
negotiator@0.6.3
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

2
All Dependencies CSV
β“˜ This is a list of accepts 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities
mime-types2.1.355.46 kBMIT
prod
negotiator0.6.36.25 kBMIT
prod

Visualizations

Frequently Asked Questions

What does accepts do?

The "accepts" is a higher-level content negotiation tool based on the negotiator library. Extracted from the koa module for general use, it's designed to simplify the process of content negotiation with clients. It enhances the functionality of the negotiator by allowing types as an array or arguments list, shorthand type names like "json", treating non-existent headers as "*", and returning false when no types match.\

How do you use accepts?

You can use the "accepts" module by installing it through the npm registry. After installation, require the module in your file and you can start using it. Here is an example:

$ npm install accepts

After installing the module you can use it as follows:

var accepts = require('accepts')
var http = require('http')
  
function app (req, res) {
  var accept = accepts(req)
  
  // the order of this list is significant; should be server preferred order
  switch (accept.type(['json', 'html'])) {
    case 'json':
      res.setHeader('Content-Type', 'application/json')
      res.write('{"hello":"world!"}')
      break;
    case 'html':
      res.setHeader('Content-Type', 'text/html')
      res.write('<b>hello, world!</b>')
      break;
    default:
      // the fallback is text/plain, so no need to specify it above
      res.setHeader('Content-Type', 'text/plain')
      res.write('hello, world!')
      break;
  }
  res.end()
}
http.createServer(app).listen(3000)

This script will handle responses based on the client's "Accept" header. It creates an HTTP server which listens on port 3000. Whenever a request comes in, it checks the "Accept" header of the incoming request and based on the content types that the client can handle, it sends a response in the most suitable format.

Where are the accepts docs?

The documentation for the "accepts" module can be found in its README file on its GitHub repository: https://github.com/jshttp/accepts. The README includes a detailed API reference as well as usage examples.