Skip to content
heff

std.remote

An API over HTTP, the C backend’s side: a server’s requests answered by the API’s real handler, over std.http.server, and a client’s transport by std.http. Each call is a POST of its frame, answered 200 with the answer’s frame; a page’s client is browser.remote’s. Import it by a name beside remote’s, import std.remote as RemoteHTTP (as browser.remote is, in a page).

contentType

contentType : String

What a frame is sent as, its Content-Type.

framed

framed : Bytes -> HTTP.Response

respond

respond : {h : HFunctor}
-> {e : HFunctor}
-> Remote.Api h
-> ({a : Type} -> h.f (Co e) a -> Co e a)
-> Server.Request
-> Co e HTTP.Response

A request answered: a POST of a call’s frame, by Remote.respond (the operation done by alg, the effect’s real handler, as through takes one), the answer’s frame its body; any other method 405.

pathOf

pathOf : String -> String

A request’s path: its target up to a ?, if it has one.

>>> List.map pathOf ["/api", "/api?x=1", "/"]
["/api", "/api", "/"]

routed

routed : {h : HFunctor}
-> {e : HFunctor}
-> String
-> Remote.Api h
-> ({a : Type} -> h.f (Co e) a -> Co e a)
-> (Server.Request -> Co e HTTP.Response)
-> Server.Request
-> Co e HTTP.Response

A server’s requests: those whose path is at ("/api") answered as respond answers them, any other by other (the page and its script, say).

exchanged

exchanged : String
-> Either HTTP.HttpError HTTP.Response
-> Either Remote.RemoteError Bytes

posted

posted : {e : HFunctor}
-> {{web : HTTP.http <: e}}
-> {timeout : Int := 0}
-> String
-> Remote.Transport e

A client’s transport: each frame a POST to the URL, by std.http, the answer the response’s body; where no response came, or one of a status that is no 200, Unreachable (a timeout, in milliseconds, 0 for none).