Skip to content

gleam-lang/hackney

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

  •  
  •  
  •  

Packages

No packages published

Contributors 3

  •  
  •  
  •