Skip to main content

HTTP

Constant HTTP 

Source
pub const HTTP: ModuleSchema;
Expand description

http: fetching over the network, and listening on a port.

The four declared types are all ordinary data: a request and a response are what crossed the wire, a method is one of two names, and a route pairs them with the callback that answers it. A handler is HostType::Any because the host never looks inside it — it stores the value and calls it.

listen is a reversible write: it takes a port from the machine, and close gives it back. fetch reads, since a GET is what it sends and nothing outside the run is different afterwards. json touches nothing at all — it is a constructor the host owns because the host owns the encoding.

http.Response is the type of both halves of this module: it is what a route’s handler answers, what json builds, and what fetch hands a client. A client and a server learn the same two facts about a response — its status and its body — so declaring them twice would have been two names for one shape, and a program that proxied one to the other would have had to copy it field by field.

The listener lives behind a lock the host owns, so two tasks may both hold the handle and take turns accepting: the resource is task-safe, and the schema is where it says so.