allowed-methods
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

allowed-methods

Allow a set of HTTP methods

CI Downloads Install size XO code style

Install

$ npm install allowed-methods

Usage

const http = require('http');
const allowedMethods = require('allowed-methods');

const handler = (req, res) => {
	res.end('success');
};

const server = http.createServer(allowedMethods(['get', 'post'])(handler));

server.listen(3001);

In serverless environment:

const allowedMethods = require('allowed-methods');

module.exports = allowedMethods(['get'])((req, res) => {
	res.end('success');
});

API

allowedMethods(methods)(handler)

methods

Type: ('get' | 'post' | 'put' | 'patch' | 'delete')[]

An array of allowed HTTP methods.

handler

Type: Function

The request handler to wrap.

Examples

See the examples for more details.

Authors

License

MIT

Package Sidebar

Install

npm i allowed-methods

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

4.38 kB

Total Files

5

Last publish

Collaborators

  • acestojanoski