Skip to content

🪝 Make requests to HTTP servers with Hackney

License

Notifications You must be signed in to change notification settings

vpribish/hackney

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 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
import gleam/result
import gleam/hackney
import gleam/http/request
import gleam/http/response
import gleeunit/should

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\"}")
}

About

🪝 Make requests to HTTP servers with Hackney

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Gleam 87.2%
  • Erlang 12.8%