1.0.2 • Published 2 years ago
micro-router v1.0.2
micro-router
Route matcher for HTTP requests.
Install
npm i micro-routerUsage
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:URLSearchParamsobject 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);