New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

koa-tree-router

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-tree-router - npm Package Compare versions

Comparing version

to
0.1.0

index.d.ts

8

package.json
{
"name": "koa-tree-router",
"version": "0.0.2",
"version": "0.1.0",
"description": "A high performance koa router",

@@ -16,2 +16,7 @@ "main": "router.js",

},
"files": [
"*.js",
"*.md",
"index.d.ts"
],
"keywords": [

@@ -31,2 +36,3 @@ "koa",

"homepage": "https://github.com/steambap/koa-tree-router#readme",
"typings": "index.d.ts",
"devDependencies": {

@@ -33,0 +39,0 @@ "beautify-benchmark": "^0.2.4",

# Koa tree router
Koa tree router a high performance router for Koa.
[![Build Status](https://travis-ci.org/steambap/koa-tree-router.svg?branch=master)](https://travis-ci.org/steambap/koa-tree-router)
Koa tree router is a high performance router for Koa.
## Features

@@ -11,2 +13,4 @@

- Support for 405 method not allowed
- Multiple middlewares per route

@@ -35,2 +39,61 @@

app.listen(8080);
```
## API
#### Router([options])
Instance a new router.
You can pass a middleware with the option `onMethodNotAllowed`.
```js
const router = require('koa-tree-router')({
onMethodNotAllowed(ctx){
ctx.body = "not allowed"
}
})
```
#### on(method, path, middleware)
Register a new route.
```js
router.on('GET', '/example', (ctx) => {
// your code
})
```
#### Shorthand methods
If you want tp get expressive, here is what you can do:
```js
router.get(path, middleware)
router.delete(path, middleware)
router.head(path, middleware)
router.patch(path, middleware)
router.post(path, middleware)
router.put(path, middleware)
router.options(path, middleware)
router.trace(path, middleware)
router.connect(path, middleware)
```
If you need a route that supports *all* methods you can use the `all` api.
```js
router.all(path, middleware)
```
#### routes
Returns router middleware.
```JS
app.use(router.routes());
```
#### ctx.params
This object contains key-value pairs of named route parameters.
```JS
router.get("/user/:name", function() {
// your code
});
// GET /user/1
ctx.params.name
// => "1"
```
.travis.yml