default_request : Request
A GET request with empty headers/body, no timeout, and an empty URI.
Override the fields you need, e.g.
{ ..Http.default_request, uri: "https://example.com" }.
:= []
HTTP requests as effects. The response arrives as a typed message:
Http.get(url, |result| GotData(result)) calls your function with a
Try(Response, ...) and feeds the resulting msg to update.
Any status the server actually sent is Ok(response), including 4xx and
5xx: an Err(HttpErr(...)) is reserved for transport failures where no
response exists at all. NetworkError means the request never completed
(network failure, CORS, ...), Timeout means the request's timeout_ms
ran out first. A match on the result covers every outcome without magic
status numbers.
default_request : Request
A GET request with empty headers/body, no timeout, and an empty URI.
Override the fields you need, e.g.
{ ..Http.default_request, uri: "https://example.com" }.
method_to_str : Method -> Str
The request method as it appears on the wire.
Full control: method, uri, headers, body, timeout.
post_file : Str, U32, List(Header), (Try(Response, [HttpErr([Timeout, NetworkError]), ..]) -> msg) -> Effect(msg)
POST a user-picked file as the request body. The file id comes from
Attribute.on_file; the browser streams the File object directly, so
the bytes never enter wasm memory (uploads of any size cost no wasm
heap).
put_file : Str, U32, List(Header), (Try(Response, [HttpErr([Timeout, NetworkError]), ..]) -> msg) -> Effect(msg)
PUT a user-picked file as the request body (see post_file).
request_file : { method : Method, uri : Str, headers : List(Header), file : U32, start : U64, len : U64, timeout_ms : [TimeoutMilliseconds(U64), NoTimeout] }, (Try(Response, [HttpErr([Timeout, NetworkError]), ..]) -> msg) -> Effect(msg)
Full control over a file-body request, including a byte range and a
timeout. start and len slice the file (len 0 means through the
end), the building block for chunked uploads of large files.
An HTTP header, e.g. { name: "Content-Type", value: "application/json" }.
An HTTP response. Any status the server sent lands here, 4xx and 5xx
included, while transport failures never produce a Response at all.
Request : {
method : Method,
uri : Str,
headers : List(Header),
body : List(U8),
timeout_ms : [TimeoutMilliseconds(U64), NoTimeout],
}
An HTTP request, for Http.request.