Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lsongdev/routing2

:triangular_flag_on_post: Parse HTTP Routing definition with no dependencies, just ~3kb!
https://github.com/lsongdev/routing2

http http-routing router routing

Last synced: 3 days ago
JSON representation

:triangular_flag_on_post: Parse HTTP Routing definition with no dependencies, just ~3kb!

Awesome Lists containing this project

README

        

## routing2

> Parse HTTP Routing definition with no dependencies, just ~3kb!

[![routing2](https://img.shields.io/npm/v/routing2.svg)](https://npmjs.org/routing2)
[![Build Status](https://travis-ci.org/song940/routing2.svg?branch=master)](https://travis-ci.org/song940/routing2)

### Define

### Installation

```bash
$ npm install routing2
```

### Example

```js
const routing = require('routing2');

const routes = routing.parse(`
get / => home#index
get /:name => user#index, { "foo": "bar" }
post /user => user#create
`);

const request = {
method: 'get',
url: '/lsong?foo=bar'
};

const route = routing.find(routes, request);

console.log(route);
// { status: 200,
// route:
// { domain: undefined,
// path: '/:name',
// action: 'index',
// controller: 'user',
// options: { foo: "bar" },
// method: 'GET' },
// params: { name: 'lsong' },
// query: { foo: 'bar' } }
```

### Contributing
- Fork this Repo first
- Clone your Repo
- Install dependencies by `$ npm install`
- Checkout a feature branch
- Feel free to add your features
- Make sure your features are fully tested
- Publish your local branch, Open a pull request
- Enjoy hacking <3

### MIT

This work is licensed under the [MIT license](./LICENSE).

---