NOTICE: 2021/04/09 servestjs.org no longer hosts typescript files. Use https://deno.land/x/servest

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://deno.land/x/[email protected]/mod.ts";
const listener = listenAndServe({ port: 8899 }, async (req) => {
  await req.respond({
    status: 200,
    headers: new Headers({
      "content-type": "text/plain",
    }),
    body: "hello",
  });
});