Server API

Server API is low level HTTP interface for building customized HTTP server.

All HTTP requests connected to the address will be passed to callback function. Serve API automatically manages Keep-Alive connection and process requests from same connection serially.

// Copyright 2019 Yusuke Sakurai. All rights reserved. MIT license.
import { listenAndServe } from "https://servestjs.org/@v0.36.0/server.ts";
const listener = listenAndServe({ port: 8899 }, async (req) => {
  await req.respond({
    status: 200,
    headers: new Headers({
      "content-type": "text/plain",
    }),
    body: "hello",
  });
});