Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Bindings to Erlang's built in HTTP client, `httpc`.
```sh
gleam add gleam_httpc@5
```

## Synchronous request

```gleam
import gleam/http/request
import gleam/http/response
Expand Down Expand Up @@ -37,6 +40,47 @@ pub fn send_request() {
}
```

## Asynchronous (i.e., Streaming) requests

```gleam
import gleam/erlang/atom
import gleam/http.{Get}
import gleam/http/request
import gleam/httpc

pub fn send_async_request() {
let req =
request.new()
|> request.set_method(Get)
|> request.set_host("postman-echo.com")
|> request.set_path("/stream/1")

let config =
httpc.configure()
|> httpc.async_stream(httpc.StreamSelf)

let assert Ok(request_id) = httpc.async_dispatch(config, req)

let assert Ok(payload) = httpc.async_receive(request_id, 1000)
// stream_start
// #(stream_start, headers)
let #(stream_start, _headers) = payload
assert atom.to_string(stream_start) == "stream_start"

// stream - 1 chunk
// #(stream, chunk)
let assert Ok(payload) = httpc.async_receive(request_id, 1000)
let #(stream, _chunk) = payload
assert atom.to_string(stream) == "stream"

// stream_end
// #(stream, end_info)
let assert Ok(payload) = httpc.async_receive(request_id, 1000)
let #(stream_end, _end_info) = payload
assert atom.to_string(stream_end) == "stream_end"
}
```

## Use with Erlang/OTP versions older than 26.0

Older versions of HTTPC do not verify TLS connections by default, so with them
Expand Down
8 changes: 4 additions & 4 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# You typically do not need to edit this file

packages = [
{ name = "gleam_erlang", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "7E6A5234F927C4B24F8054AB1E4572206C41F9E6D5C6C02273CB7531E7E5CED0" },
{ name = "gleam_http", version = "4.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "0A62451FC85B98062E0907659D92E6A89F5F3C0FBE4AB8046C99936BF6F91DBC" },
{ name = "gleam_stdlib", version = "0.60.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "621D600BB134BC239CB2537630899817B1A42E60A1D46C5E9F3FAE39F88C800B" },
{ name = "gleeunit", version = "1.5.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D33B7736CF0766ED3065F64A1EBB351E72B2E8DE39BAFC8ADA0E35E92A6A934F" },
{ name = "gleam_erlang", version = "1.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "1124AD3AA21143E5AF0FC5CF3D9529F6DB8CA03E43A55711B60B6B7B3874375C" },
{ name = "gleam_http", version = "4.1.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_http", source = "hex", outer_checksum = "DD0271B32C356FB684EC7E9F48B1E835D0480168848581F68983C0CC371405D4" },
{ name = "gleam_stdlib", version = "0.62.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "0080706D3A5A9A36C40C68481D1D231D243AF602E6D2A2BE67BA8F8F4DFF45EC" },
{ name = "gleeunit", version = "1.6.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "FDC68A8C492B1E9B429249062CD9BAC9B5538C6FBF584817205D0998C42E1DAC" },
]

[requirements]
Expand Down
Loading