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.

import { listenAndServe } from "https://servestjs.org/@v1.1.0/mod.ts";
const listener = listenAndServe({ port: 8899 }, async (req) => {
  await req.respond({
    status: 200,
    headers: new Headers({
      "content-type": "text/plain",
    }),
    body: "hello",
  });
});