https://github.com/serviejs/servie-route
Simple route middleware for Servie
https://github.com/serviejs/servie-route
http method route router servant verb
Last synced: 6 months ago
JSON representation
Simple route middleware for Servie
- Host: GitHub
- URL: https://github.com/serviejs/servie-route
- Owner: serviejs
- License: other
- Created: 2017-01-20T21:53:45.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-12-12T07:33:37.000Z (over 2 years ago)
- Last Synced: 2024-12-17T20:43:48.137Z (over 1 year ago)
- Topics: http, method, route, router, servant, verb
- Language: TypeScript
- Size: 766 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Servie Route
[](https://npmjs.org/package/servie-route)
[](https://npmjs.org/package/servie-route)
[](https://travis-ci.org/serviejs/servie-route)
[](https://coveralls.io/r/serviejs/servie-route?branch=master)
> Simple route middleware for Servie using [Path-To-Regexp](https://github.com/pillarjs/path-to-regexp).
## Installation
```
npm install servie-route --save
```
## Usage
The package exposes common HTTP methods: `get`, `head`, `put`, `post`, `patch`, `del`, and `options`.
```ts
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])]);
})
]);
```
### Composition
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 a [`path-to-regexp`](https://github.com/pillarjs/path-to-regexp) path.
## TypeScript
This project is written using [TypeScript](https://github.com/Microsoft/TypeScript) and publishes the definitions directly to NPM.
## License
Apache 2.0