JSPM

blvd-methods

2.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q19955F
  • License MIT

Method combinators for HTTP handlers

Package Exports

  • blvd-methods

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (blvd-methods) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.