Skip to content

Commit b295c96

Browse files
committed
v1.3.2
1 parent 1d57ba3 commit b295c96

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

README.md

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
# Hackney
22

3-
<a href="https://github.com/gleam-lang/hackney/releases"><img src="https://img.shields.io/github/release/gleam-lang/hackney" alt="GitHub release"></a>
4-
<a href="https://discord.gg/Fm8Pwmy"><img src="https://img.shields.io/discord/768594524158427167?color=blue" alt="Discord chat"></a>
3+
[![Package Version](https://img.shields.io/hexpm/v/gleam_hackney)](https://hex.pm/packages/gleam_hackney)
4+
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/gleam_hackney/)
55

66
Bindings to Erlang's `hackney` HTTP client.
77

8+
Most the time [`gleam_httpc`](https://github.com/gleam-lang/httpc) is a better
9+
choice as it uses the built-in Erlang HTTP client, but this package may be
10+
useful in some specific situations.
11+
12+
```shell
13+
gleam add gleam_hackney@1
14+
```
815
```gleam
9-
import gleam/result.{try}
16+
import gleam/result
1017
import gleam/hackney
1118
import gleam/http.{Get}
1219
import gleam/http/request
@@ -19,29 +26,19 @@ pub fn main() {
1926
request.to("https://test-api.service.hmrc.gov.uk/hello/world")
2027
2128
// Send the HTTP request to the server
22-
use response <- try(
29+
use response <- result.try(
2330
request
2431
|> request.prepend_header("accept", "application/vnd.hmrc.1.0+json")
2532
|> hackney.send
2633
)
2734
2835
// We get a response record back
29-
response.status
30-
|> should.equal(200)
31-
32-
response
33-
|> response.get_header("content-type")
34-
|> should.equal(Ok("application/json"))
36+
assert response.status == 200
3537
36-
response.body
37-
|> should.equal("{\"message\":\"Hello World\"}")
38+
assert response.get_header(response, "content-type")
39+
== Ok("application/json")
3840
39-
Ok(response)
41+
assert response.body
42+
== "{\"message\":\"Hello World\"}")
4043
}
4144
```
42-
43-
## Installation
44-
45-
```shell
46-
gleam add gleam_hackney
47-
```

0 commit comments

Comments
 (0)