std/Http

import { serve } from "https://deno.land/std/http/server.ts";
const s = serve({ port: 8000 });
console.log("http://localhost:8000/");
for await (const req of s) {
  req.respond({ body: "Hello World\n" });
}
Copy the code

Server. Ts source

Exposed apis:

  • ServerRequest
export class ServerRequest {
  // logic
}
Copy the code
  • Server
export class Server implements AsyncIterable<ServerRequest> {
  private closing = false;
  private connections: Conn[] = [];

  constructor(public listener: Listener) { }
  close(): void {}
  private async *iterateHttpRequests(
    conn: Conn
  ): AsyncIterableIterator<ServerRequest> {}
  private trackConnection(conn: Conn): void {}
  private untrackConnection(conn: Conn): void {}
  private async *acceptConnAndIterateHttpRequests(
    mux: MuxAsyncIterator<ServerRequest>
  ): AsyncIterableIterator<ServerRequest> {}
  [Symbol.asyncIterator](): AsyncIterableIterator<ServerRequest> {}
}
Copy the code
  • serve
function serve(addr: string | HTTPOptions) :Server {
  if (typeof addr === "string") {
    const [hostname, port] = addr.split(":");
    addr = { hostname, port: Number(port) };
  }

  const listener = listen(addr);
  return new Server(listener);
}
Copy the code
  • listenAndServe
export async function listenAndServe(
  addr: string | HTTPOptions,
  handler: (req: ServerRequest) => void
): Promise<void> {}
Copy the code
  • serveTLS
export function serveTLS(options: HTTPSOptions) :Server {}
Copy the code
  • Response
export interface Response {}
Copy the code

Iterable asynchronous services

Instances of the Server class are iterable, internally wrapped with REQ, RES response objects

  • Server internal implementation

HTTP module standard library

  • io
  • cookie
  • file_server
  • http_bench
  • http_status
  • mod
  • racing_server
  • server