1.0.2 • Published 1 year ago

@congritta/http-server v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

My own NodeJS REST API implementation

I don't like express.js. This is too weak HTTP framework for building serious projects. It is even not available to read POST data out of box.

I decided to write my own HTTP server implementation that allows get most features (reading POST data, context and so on) without installing any HTTP framework.

Warning: works only on Linux systems cause I hate Windows

Docs Site

https://git.congritta.com/http-server-docs

At the moment, my implementation`s features:

  • Built on native node http server;
  • Written in Typescript;
  • All server staff in Server class;
  • Middleware support;
  • Context over middlewares and handlers support;
  • Custom request and response objects with only needed staff;
  • Can read POST data out of box. JSON, multipart/form-data, urlencoded supported;
  • CORS implements automatically when server is running in development mode
  • Request logging when server is running in development mode

How to install

npm i @congrita/http-server

Server example

import Server, {Response} from "@congritta/http-server";
// or commonjs:
// const {default: Server, Response} = require("@congritta/http-server")

const server = new Server(3001, '127.0.0.1');

server.on("GET", "/", () => {
  return new Response(200, "Hello World");
});

server.run().then(() => {
  consola.ready(`HTTP Server started at http://${server.host}:${server.port}`);
});