Simple route middleware for Servie using Path-To-Regexp.
npm install servie-route --save
The package exposes common HTTP methods: get
, head
, put
, post
, patch
, del
, and options
.
import { get, post } from "servie-route";
import { compose } from "throwback";
const animals = ["rabbit", "dog", "cat"];
const app = compose([
get("/pets", function() {
return new Response(animals.join("\n"));
}),
get("/pets/:id", function(req) {
return new Response(animals[Number(req.params[0])]);
})
]);
If you need raw control, the package also exposes the internally used functions: method
and path
.
method(method, fn)
- Match an incoming request against a HTTP method.path(path, fn, options?)
- Match an incoming request against apath-to-regexp
path.
This project is written using TypeScript and publishes the definitions directly to NPM.
Apache 2.0