Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

blvd-methods

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blvd-methods

Method combinators for HTTP handlers

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
1
Created
Source

blvd-methods
npm version Build status

Combinators to wrap HTTP handlers and filter based on method.

http.createServer(methods.put(function(req, res) {
  assert(req.method === 'put');
}));

Supports every method that Node HTTP does.

Custom method getting

If you're using something other than Node HTTP, and req isn't the first argument to the handler, or the method is somewhere other than req.method, you can override getMethod using underscored methods:

var get = methods.get_(function getMethod() {
  return this.method; // e.g. Koa
});

get(function *(next) {
  // ...
});

Or override them all at once with withGetMethod:

var methods = require('blvd-methods').withGetMethod(function getMethod() {
  return this.method; // e.g. Koa
});

methods.get(function *(next) {
  // ...
});

Routing

blvd-methods is designed to work well with Boulevard routers:

route([
  ['/',  methods.get(function(req, res) { /* ... */})],
  ['/', methods.post(function(req, res) { /* ... */})],
]);

Licence

MIT.

Keywords

http

FAQs

Package last updated on 08 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts