httprouter-js
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

HttpRouter

NPM Version Node Version

Super fast web router for node.js, rewritten from golang's httprouter

Installation

npm i httprouter-js -S

Usage

import { createServer, IncomingMessage, ServerResponse } from "http";
import { Router } from "httprouter-js";
 
const router = new Router();
 
function Index(res: ServerResponse, req: IncomingMessage, params: any) {
  res.write(
    "Welcome! " +
      (params ? params.find((v: any) => v.Key === "name").Value : "")
  );
  res.end();
}
 
router.GET("/another", Index);
router.GET("/hello/:name", Index);
 
const server = createServer(router.ServeHTTP.bind(router));
 
server.listen(3000);
console.log("Listening on 3000..");

Todo

  • middleware
  • adapter for express or koa

License

MIT

Dependents (0)

Package Sidebar

Install

npm i httprouter-js

Weekly Downloads

2

Version

1.0.4

License

MIT

Unpacked Size

26.1 kB

Total Files

8

Last publish

Collaborators

  • cooperhsiung