Std.Http
View source →Minimal HTTP client (v0.23.0).
Thin wrapper over OTP's :httpc; no external dependencies.
Produces Result(Response, HttpError) so callers can compose
HTTP with regular Result-chains.
Response.headers is a list of (name, value) string pairs.
Examples
use Std.Http
match get("https://example.com/api")
Ok(resp) -> resp.status # => 200
Error(_) -> 0
use Std.Http
# POST a JSON payload.
let headers = [("Content-Type", "application/json")]
let body = <<"{\"hello\":\"world\"}">>
post("https://example.com/api", headers, body)
Types
-
type HttpError = Timeout | BadStatus | NetworkError | DecodeErrorTagged error returned by every HTTP call.
Functions
-
# fn __group__() -> Atom
Group tag consumed by
Cure.Stdlib.Preload. -
# fn get(url: String) -> Result(Response, HttpError) extern
Issue a GET request.
-
# fn get_with_headers(url: String, headers: List(%[String, String])) -> Result(Response, HttpError) extern
Issue a GET with custom request headers.
-
# fn head(url: String) -> Result(Response, HttpError) extern
Issue a HEAD request; useful for probing without downloading the body.
-
# fn post(url: String, headers: List(%[String, String]), body: Bitstring) -> Result(Response, HttpError) extern
Issue a POST.
bodyis sent verbatim as the request body; setContent-Typeviaheadersas appropriate.