http-method-filter

1.1.2 • Public • Published

Build Status

http-method-filter

HTTP Method filter middleware for Express

Whitelist HTTP methods for an app or route.

All other HTTP methods will be rejected.

httpMethodFilter(whitelist[, statusCode])

  • whitelist - array of allowed HTTP methods
  • statusCode - Default: 405 set the HTTP status code of the response

Usage:

import httpFilter from 'http-method-filter';
import express from 'express';

const app = express();

// Entire express app
app.use(httpFilter(['POST']));
app.use('*', httpFilter(['POST']));

// For specific route
app.all('/api/path', httpFilter(['GET']), (req, res, next) => {

});

// With express router
router.all('/api/path', httpFilter(['POST', 'GET']));
router.route('/')
  .all(httpFilter(['POST', 'GET']))
  .get(...)
// With status code
router.route('/')
  .all(httpFilter(['POST', 'GET'], 500))
  .get(...)

Package Sidebar

Install

npm i http-method-filter

Weekly Downloads

3

Version

1.1.2

License

ISC

Last publish

Collaborators

  • jacobtshirt