diff options
author | HJ <thechairman@thechairman.info> | 2024-02-03 15:09:54 -0500 |
---|---|---|
committer | HJ <thechairman@thechairman.info> | 2024-02-03 15:09:54 -0500 |
commit | 96a3c5c179d8d3fff24eb2953e45f8dd15e2714c (patch) | |
tree | 0a67bc0cfeabe51740bb049c61f16f1ac3bdd4ff /aoc2023/build/packages/gleam_httpc/README.md | |
parent | 547fe03cf43105f46160e2dd9afff21637eaaf47 (diff) | |
download | gleam_aoc-96a3c5c179d8d3fff24eb2953e45f8dd15e2714c.tar.gz gleam_aoc-96a3c5c179d8d3fff24eb2953e45f8dd15e2714c.zip |
cleanup
Diffstat (limited to 'aoc2023/build/packages/gleam_httpc/README.md')
-rw-r--r-- | aoc2023/build/packages/gleam_httpc/README.md | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/aoc2023/build/packages/gleam_httpc/README.md b/aoc2023/build/packages/gleam_httpc/README.md new file mode 100644 index 0000000..c2363c5 --- /dev/null +++ b/aoc2023/build/packages/gleam_httpc/README.md @@ -0,0 +1,52 @@ +# httpc +<a href="https://github.com/gleam-lang/httpc/releases"><img src="https://img.shields.io/github/release/gleam-lang/httpc" alt="GitHub release"></a> +<a href="https://discord.gg/Fm8Pwmy"><img src="https://img.shields.io/discord/768594524158427167?color=blue" alt="Discord chat"></a> + + +Bindings to Erlang's built in HTTP client, `httpc`. + +```gleam +import gleam/httpc +import gleam/http.{Get} +import gleam/http/request +import gleam/http/response +import gleeunit/should + +pub fn main() { + // Prepare a HTTP request record + let request = 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 = 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) +} +``` + +## Installation + +```shell +gleam add gleam_httpc +``` + +## 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). |