Skip to content

CrowdHailer/hackney

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hackney

Package Version Hex Docs

Bindings to Erlang's hackney HTTP client.

Most the time gleam_httpc is a better choice as it uses the built-in Erlang HTTP client, but this package may be useful in some specific situations.

gleam add gleam_hackney@1 gleam_http
import gleam/result
import gleam/hackney
import gleam/http/request
import gleam/http/response

pub fn main() {
  // Prepare a HTTP request record
  let assert Ok(request) =
    request.to("https://test-api.service.hmrc.gov.uk/hello/world")

  // Send the HTTP request to the server
  use response <- result.try(
    request
    |> request.prepend_header("accept", "application/vnd.hmrc.1.0+json")
    |> hackney.send
  )

  // We get a response record back
  assert response.status == 200

  assert response.get_header(response, "content-type")
    == Ok("application/json")

  assert response.body
    == "{\"message\":\"Hello World\"}"

  Ok(response)
}

About

🪝 Make requests to HTTP servers with Hackney

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Gleam 88.7%
  • Erlang 11.3%