1.1.2 • Published 7 years ago

http-method-filter v1.1.2

Weekly downloads
1
License
ISC
Repository
github
Last release
7 years ago

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(...)
1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago

0.1.1

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago