Install gleam_httpc
mainTo use the httpc bindings in your Gleam project, add the package using the Gleam CLI.
gleam add gleam_httpc@5repository·main·Indexed 41 days ago
https://github.com/gleam-lang/httpcGleam bindings to Erlang's built-in HTTP client for making HTTP requests within the Erlang ecosystem.
To use the httpc bindings in your Gleam project, add the package using the Gleam CLI.
gleam add gleam_httpc@5If you are using Erlang/OTP versions older than 26.0, httpc does not verify TLS connections by default. This means connections to HTTPS endpoints may not be secure.
To ensure security, you should:
hackney.The httpc library provides bindings to Erlang's built-in HTTP client. To send a request, you typically use gleam/http/request to construct a request record and then pass it to httpc.send/1.
Note that httpc.send returns a Result containing a response record. You should handle the result (e.g., using result.try) to access the response status, headers, and body.
import gleam/http/request
import gleam/http/response
import gleam/httpc
import gleam/result
pub fn send_request() {
// Prepare a HTTP request record
let assert Ok(base_req) =
request.to("https://test-api.service.hmrc.gov.uk/hello/world")
let req =
request.prepend_header(base_req, "accept", "application/vnd.hmrc.1.0+json")
// Send the HTTP request to the server
use resp <- result.try(httpc.send(req))
// We get a response record back
assert resp.status == 200
let content_type = response.get_header(resp, "content-type")
assert content_type == Ok("application/json")
assert resp.body == "{\"message\":\"Hello World\"}"
Ok(resp)
}