micro-router
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

micro-router

Route matcher for HTTP requests.

Install

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:

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);

Readme

Keywords

none

Package Sidebar

Install

npm i micro-router

Weekly Downloads

27

Version

1.0.2

License

none

Unpacked Size

4.76 kB

Total Files

6

Last publish

Collaborators

  • darlanalves