4.3.0 • Published 2 years ago

sbx-http-lib v4.3.0

Weekly downloads
6
License
MIT
Repository
-
Last release
2 years ago

Sbx Http

Install

npm i bunyan inversify
npm i git+ssh://git@gitlab.com:stackbox-group/libs/sbx-http.git#1.0.0

Sample

import * as http from "http";
import { Container } from "inversify";
import * as Logger from "bunyan";
import {
  createHttpHandler,
  RequestResponseLogger,
  Controller,
  Context,
  Get
} from "sbx-http";

const di = new Container({ autoBindInjectable: true, defaultScope: "Request" });
const log = Logger.createLogger({ name: "sample" });

@Controller("/hello")
class TestController {
  @Get("/v1")
  async test(ctx: Context) {
    ctx.body = {
      message: "world"
    };
  }
}

const handler = createHttpHandler()({
  applicationName: "sample-app",
  applicationVersion: "1.0.0",
  compress: true,
  controllers: [TestController],
  di,
  isHealthy: () => true,
  log,
  middlewares: [RequestResponseLogger({})],
  onRequestCompleted: (method, prefix, path, time) => {
    log.info(`Timing: ${method} ${prefix} - ${path} = ${time} ms`);
  }
});

http.createServer(handler).listen(3000);
4.1.0

2 years ago

4.0.0

2 years ago

4.3.0

2 years ago

4.2.0

2 years ago

3.0.0

3 years ago

2.3.0

3 years ago

2.4.0

3 years ago

2.2.0

3 years ago

2.1.0

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago