Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/paveldeuce/router
Lightweight library to provide an API for handling routes
https://github.com/paveldeuce/router
algorithm algorithms constraints eslint-prettier jest jsdoc methods rest-api router routes tree tree-structure trie trie-tree
Last synced: 8 days ago
JSON representation
Lightweight library to provide an API for handling routes
- Host: GitHub
- URL: https://github.com/paveldeuce/router
- Owner: PavelDeuce
- Created: 2022-05-04T11:56:59.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-08-15T20:43:45.000Z (over 2 years ago)
- Last Synced: 2023-03-05T16:08:17.134Z (over 1 year ago)
- Topics: algorithm, algorithms, constraints, eslint-prettier, jest, jsdoc, methods, rest-api, router, routes, tree, tree-structure, trie, trie-tree
- Language: JavaScript
- Homepage:
- Size: 118 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# router
[![Node CI](https://github.com/PavelDeuce/router/actions/workflows/nodejs.yml/badge.svg)](https://github.com/PavelDeuce/router/actions/workflows/nodejs.yml)
[![Actions Status](https://github.com/PavelDeuce/js-algorithms-trees-project-lvl1/workflows/hexlet-check/badge.svg)](https://github.com/PavelDeuce/js-algorithms-trees-project-lvl1/actions)
[![Maintainability](https://api.codeclimate.com/v1/badges/cf29babbd64a5ec941bc/maintainability)](https://codeclimate.com/github/PavelDeuce/router/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/cf29babbd64a5ec941bc/test_coverage)](https://codeclimate.com/github/PavelDeuce/router/test_coverage)## About
Lightweight library to provide an API for handling routes
## Example
```javascript
import buildRouter from '@hexlet/code';const routes = [
{
path: '/courses/:course_id/exercises/:id',
constraints: { id: /\d+/, course_id: (courseId) => courseId.startsWith('js') },
handler: () => 'exercise!',
},
];const router = buildRouter(routes);
const result = router.serve({ path: '/courses/1/exercises/js' });
// { handler: [Function handler] , path: '/courses/1/exercises/js', params: { id: '1', course_id: 'js' }, method: 'GET' }
result.handler(result.params); // exercise!router.serve('/courses/noop/exercises/noop'); // Error: No such path
```