Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

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

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 URL

Node.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);
```