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

1.1.1 • Public • Published

npm version Build Status codecov.io

const { createServer } = require('http');
const { default: mid } = require('midmare');
const { Router: { HttpRouter, delegateHttp } } = require('midmare-http-router');

// HTTP ROUTER
const app = mid();
const httpRouter = new HttpRouter();

// Use named function declaration to 
httpRouter.process('/', function get(ctx) {
    ctx.status = 200;
    ctx.body = { ololo:1 };
});
app.use(httpRouter).init();

// Be sure that you use `delegateHttp` on app.
// delegateHttp make app understand that at some moment you will get request response object. And it will be injected to context.
createServer(delegateHttp(app)).listen(3000);

Readme

Keywords

Package Sidebar

Install

npm i midmare-http-router

Weekly Downloads

0

Version

1.1.1

License

ISC

Unpacked Size

34.5 kB

Total Files

7

Last publish

Collaborators

  • senior.wolfman