@samlior/http-server
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

@samlior/http-server

@samlior/http-server is an interruptible HTTP server based on JSONRPC.

Install

npm install @samlior/http-server

Usage

import { HTTPServer, IHTTPHanlder } from "@samlior/http-server";

class MockEchoHandler implements IHTTPHanlder {
  async handle(params: any): Promise<string> {
    if (typeof params !== "string") {
      throw new Error("invalid params");
    }
    return params;
  }
}

const { server, httpServer, terminator } = await HTTPServer.create(
  {
    maxTokens: 10,
  },
  "/",
  8080
);

// register handler
server.register("echo", new MockEchoHandler());

// start
server.start();

process.on("SIGINT", async () => {
  // this function will ensure that all executing requests are completed
  // and safely close all client connections
  await HTTPServer.shutdown(server, terminator);

  // do something...

  process.exit(0);
});

Readme

Keywords

none

Package Sidebar

Install

npm i @samlior/http-server

Weekly Downloads

1

Version

2.0.1

License

GPL-3.0-or-later

Unpacked Size

21.5 kB

Total Files

8

Last publish

Collaborators

  • samlior_