Error type for HTTP operations (a human-readable message).
Module Http
HTTP request and response types, plus client and server operations.
Request and response bodies are Bytes.Reader<Error> values, so body data can
be consumed incrementally.
type Http.Request = (String, Url, List<(String) Bytes>) Bytes.Reader<Http.Error>
An HTTP request with shape (method) (url) (headers) body.
Use let (method, url, headers) body = request to name its parts.
type Http.Response = (Nat, List<(String) Bytes>) Bytes.Reader<Http.Error>
An HTTP response with shape (status) (headers) body.
Use let (status, headers) body = response to name its parts.
dec Http.Fetch : [Http.Request] Result<Http.Error, Http.Response>
Sends an HTTP request and returns the response.
let try url = Url.FromString("https://example.com")
let try (status, headers) body = Http.Fetch(
("GET")
(url)
(*())
Bytes.EmptyReader
)
dec Http.Listen : [String] recursive either { .incoming (Http.Request, [Http.Response] Result<Http.Error, !>) self, .shutdown Result<Http.Error, !>, }
Http.Listen(address) starts an HTTP server on address,
such as "127.0.0.1:8080".
Returns a recursive stream of events:
.shutdown result— the server has shut down (e.g. on Ctrl+C or error)..incoming(request, respond) next— a request arrived. Callrespondwith aResponseto send the reply. The result indicates if sending succeeded.
Http.Listen("127.0.0.1:8080").begin.case {
.shutdown try! => ...,
.incoming(request, respond) next => {
let (method, url, headers) body = request
body.close
respond((200, *()) Bytes.EmptyReader)
next.loop
}
}