Skip to content

🪝 Make requests to HTTP servers with Hackney

License

Notifications You must be signed in to change notification settings

gleam-lang/hackney

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Feb 6, 2025
0901d6d · Feb 6, 2025

History

33 Commits
Dec 7, 2024
Dec 7, 2024
Mar 2, 2023
Dec 26, 2021
Feb 6, 2025
Dec 26, 2021
Feb 6, 2025
Feb 6, 2025
Feb 6, 2025

Repository files navigation

Hackney

GitHub release Discord chat

Bindings to Erlang's hackney HTTP client.

import gleam/result.{try}
import gleam/hackney
import gleam/http.{Get}
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 <- try(
    request
    |> request.prepend_header("accept", "application/vnd.hmrc.1.0+json")
    |> hackney.send
  )

  // We get a response record back
  response.status
  |> should.equal(200)

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

  response.body
  |> should.equal("{\"message\":\"Hello World\"}")

  Ok(response)
}

Installation

gleam add gleam_hackney