No description
Find a file
Louis Pilfold e46fe539f2
Some checks failed
test / test (push) Has been cancelled
Update test
2025-07-12 22:50:20 +01:00
.github/workflows Adjust names 2025-06-12 22:43:57 +01:00
src remove deprecated function usage 2025-07-09 14:57:52 +01:00
test Update test 2025-07-12 22:50:20 +01:00
.gitignore Use Gleam build tool 2021-11-26 22:54:23 +00:00
CHANGELOG.md v5.0.0 2025-07-12 22:46:09 +01:00
gleam.toml v5.0.0 2025-07-12 22:46:09 +01:00
LICENSE Hello, world! 2020-01-21 23:10:13 +00:00
manifest.toml Adjust names 2025-06-12 22:43:57 +01:00
README.md v5.0.0 2025-07-12 22:46:09 +01:00

httpc

Bindings to Erlang's built in HTTP client, httpc.

Package Version Hex Docs

gleam add gleam_httpc@5
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)
}

Use with Erlang/OTP versions older than 26.0

Older versions of HTTPC do not verify TLS connections by default, so with them your connection may not be secure when using this library. Consider upgrading to a newer version of Erlang/OTP, or using a different HTTP client such as hackney.