Hackney
Bindings to Erlang’s hackney
HTTP client.
import gleam/hackney
import gleam/http.{Get}
import gleam/http/request
import gleeunit/should
pub fn main() {
// Prepare a HTTP request record
let req = request.new()
|> request.set_method(Get)
|> request.set_host("test-api.service.hmrc.gov.uk")
|> request.set_path("/hello/world")
|> request.prepend_header("accept", "application/vnd.hmrc.1.0+json")
// Send the HTTP request to the server
try resp = hackney.send(req)
// We get a response record back
resp.status
|> should.equal(200)
resp
|> http.get_resp_header("content-type")
|> should.equal(Ok("application/json"))
resp.body
|> should.equal("{\"message\":\"Hello World\"}")
Ok(resp)
}
Installation
gleam add gleam_hackney