Skip to content
/ httpc Public
forked from gleam-lang/httpc

📡 Make requests to HTTP servers with httpc

License

Notifications You must be signed in to change notification settings

sobolevn/httpc

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

httpc

GitHub release Discord chat CI

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

gleam add gleam_httpc@4
import gleam/http/request
import gleam/http/response
import gleam/httpc
import gleam/result
import gleeunit/should

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
  resp.status
  |> should.equal(200)

  resp
  |> response.get_header("content-type")
  |> should.equal(Ok("application/json"))

  resp.body
  |> should.equal("{\"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.

About

📡 Make requests to HTTP servers with httpc

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Gleam 89.7%
  • Erlang 10.3%