Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gleam-lang/httpc
📡 Make requests to HTTP servers with httpc
https://github.com/gleam-lang/httpc
erlang gleam http-client
Last synced: 27 days ago
JSON representation
📡 Make requests to HTTP servers with httpc
- Host: GitHub
- URL: https://github.com/gleam-lang/httpc
- Owner: gleam-lang
- License: apache-2.0
- Created: 2020-01-21T17:21:45.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-11-10T16:39:35.000Z (about 1 month ago)
- Last Synced: 2024-11-10T17:34:07.475Z (about 1 month ago)
- Topics: erlang, gleam, http-client
- Language: Gleam
- Homepage: https://hexdocs.pm/gleam_httpc/
- Size: 66.4 KB
- Stars: 81
- Watchers: 4
- Forks: 14
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-gleam - gleam_httpc - [📚](https://hexdocs.pm/gleam_httpc/) - Gleam bindings to Erlang's built in HTTP client, httpc (Packages / HTTP Clients)
README
# httpc
![CI](https://github.com/gleam-lang/httpc/workflows/test/badge.svg?branch=main)Bindings to Erlang's built in HTTP client, `httpc`.
```shell
gleam add gleam_httpc@3
```
```gleam
import gleam/http/request
import gleam/http/response
import gleam/httpc
import gleam/result
import gleeunit/shouldpub fn send_request() {
// Prepare a HTTP request record
let assert Ok(base_req) =
request.to("https://test-api.service.hmrc.gov.uk/hello/world")let req =
request.prepend_header(base_req, "accept", "application/vnd.hmrc.1.0+json")// Send the HTTP request to the server
use resp <- result.try(httpc.send(req))// We get a response record back
resp.status
|> should.equal(200)resp
|> response.get_header("content-type")
|> should.equal(Ok("application/json"))resp.body
|> should.equal("{\"message\":\"Hello World\"}")Ok(resp)
}
```## Use with Erlang/OTP versions older than 26.0
Older versions of HTTPC do not verify TLS connections by default, so with them
your connection may not be secure when using this library. Consider upgrading to
a newer version of Erlang/OTP, or using a different HTTP client such as
[hackney](https://github.com/gleam-lang/hackney).