Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gleam-lang/hackney

🪝 Make requests to HTTP servers with Hackney
https://github.com/gleam-lang/hackney

erlang gleam http-client

Last synced: about 2 months ago
JSON representation

🪝 Make requests to HTTP servers with Hackney

Awesome Lists containing this project

README

        

# Hackney

GitHub release
Discord chat
![CI](https://github.com/gleam-lang/hackney/workflows/test/badge.svg?branch=main)

Bindings to Erlang's `hackney` HTTP client.

```gleam
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

```shell
gleam add gleam_hackney
```