the-http-router

router for the-http

Usage no npm install needed!

<script type="module">
  import theHttpRouter from 'https://cdn.skypack.dev/the-http-router';
</script>

README

The HTTP Router

Router for the-http.

Install

npm install --save the-http-router

Usage

const {listen} = require(
const route = require('the-http-router')

const hanlder = route([
  ['GET', '/hello' () => Response.withTextBody('hello world')],
  [['GET', POST'], '/hi/:name', (request) => Response.withTextBody(`hi ${request.params.name}`),
])

listen(3000)(handler)

API

route(routes, options?)

  • {Array} routes - item is [method, path, handler]
    • handler is THHandler
    • request.params is added to hold route params
    • see find-my-way to learn more about method and path
  • {Object} [options]
  • {function} [options.defaultHandler]

License MIT