Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dot-build/micro-router
A tiny router for Node.js
https://github.com/dot-build/micro-router
Last synced: about 1 month ago
JSON representation
A tiny router for Node.js
- Host: GitHub
- URL: https://github.com/dot-build/micro-router
- Owner: dot-build
- Created: 2015-05-26T05:35:00.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2024-01-21T11:31:43.000Z (12 months ago)
- Last Synced: 2024-04-14T08:30:17.491Z (9 months ago)
- Language: JavaScript
- Homepage:
- Size: 11.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# micro-router
Route matcher for HTTP requests.
## Install
```sh
npm i micro-router
```## Usage
Every route function is called with `(request, response, params, queryParams)`.
- `request/response`: values come from the http server.
- `params`: Object. Keys are items in the path, like `{id}`.
- `queryParams`: `URLSearchParams` object from the request URLNode.JS example:
```ts
import router from 'micro-router'
import { createServer } from 'http';const routes = {
'GET /user/{id}': onUserGet,
'DELETE /user/:id': onUserRemove,
'POST /auth': onAuthenticate,
};const fn = router(routes);
createServer(fn).listen(1234);
```