netkit/http/server

This module implements an HTTP server.

Types

AsyncHttpServer = ref object
  socket: AsyncFD
  domain: Domain
  onRequest: RequestHandler
  closed: bool
Server object.   Source Edit
RequestHandler = proc (req: ServerRequest; res: ServerResponse): Future[void] {...}{.closure,
    gcsafe.}
  Source Edit

Procs

proc newAsyncHttpServer(): AsyncHttpServer {...}{.raises: [], tags: [].}
Creates a new AsyncHttpServer 。   Source Edit
proc onRequest=(server: AsyncHttpServer; handler: RequestHandler) {...}{.raises: [],
    tags: [].}
Sets a hook proc for the server. Whenever a new request comes, this hook function is triggered.   Source Edit
proc close(server: AsyncHttpServer) {...}{.raises: [Exception], tags: [RootEffect].}
Closes the server to release the underlying resources.   Source Edit
proc serve(server: AsyncHttpServer; port: Port; address: string = ""; domain = AF_INET): owned(
    Future[void]) {...}{.raises: [Exception, FutureError],
                   tags: [WriteIOEffect, ReadIOEffect, RootEffect].}
Starts the process of listening for incoming HTTP connections on the specified address and port.   Source Edit