Type-safe HTTP client for Gleam with streaming support
dream_http_client
Type-safe HTTP client for Gleam with recording + streaming support.
A standalone HTTP and HTTPS client built on gun. It supports HTTP/1.1 and HTTP/2 with native multiplexing. It gives blocking requests, yielder streaming, process-based streaming with callbacks, and message-based streaming to OTP actors. It is built with the same quality standards as Dream, but it is completely independent. Use it in any Gleam project.
Features
| Feature | What you get |
|---|---|
| Four execution modes | Blocking, yielder streaming, process-based, and actor messages |
| OTP-first design | Process-based streams work well with OTP |
| Recording/playback | Record HTTP calls for tests, debug production, work offline |
| Type-safe | Result types force error handling, with no silent failures |
| HTTP/2 ready | Native HTTP/2 multiplexing via gun for high concurrency |
| Framework-independent | Zero dependencies on Dream or other frameworks |
| Concurrent streams | Handle multiple HTTP streams in a single actor |
| Stream cancellation | Cancel in-flight requests cleanly |
| Builder pattern | Consistent, composable request configuration |
Installation
gleam add dream_http_client
Quick Start
Send a request and print the answer:
Send a request and print the answer

import dream_http_client/client.{
type HttpResponse, host, path, port, scheme, send,
}
import gleam/http
import gleam/int
import gleam/io
import gleam/result
import gleam/string
pub fn main() -> Nil {
let request =
client.new()
|> scheme(http.Http)
|> host("localhost")
|> port(9876)
|> path("/text")
case send(request) {
Ok(response) -> print_response(response)
Error(error) -> io.println("The request failed: " <> string.inspect(error))
}
}
fn print_response(response: HttpResponse) -> Nil {
let text = client.body_text(response) |> result.unwrap("<not text>")
io.println("Status: " <> int.to_string(response.status))
io.println("Body: " <> text)
}
Guides
- Getting started: go from an empty project to a tested module that calls an API and decodes its JSON
- Sending data to an API: POST, PUT, PATCH and DELETE JSON, send query strings, tokens and bytes, and read response headers
- Handling errors, timeouts and retries: tell each failure apart, set timeouts and redirects, retry safely, and know when the client sends a request again
- Streaming a response: read a long or endless response chunk by chunk, handle failures, and test it
- Streaming into an OTP actor: handle a stream as typed messages in an actor that keeps state and answers other messages
- Controlling connections: see how connections are shared, use HTTP/2, set limits, give one caller its own pool, and read the log
- Calling a service with a private certificate authority: trust an internal certificate authority for one service or for all requests, and test it over TLS
- Testing with recorded responses: record real API calls once and play them back in tests with no network
- Matching requests and hiding secrets in recordings: choose which recording answers a request, and keep tokens and cookies out of the files
- Settings reference: every request, transport and recorder setting with its default
API Reference
The full API reference is on HexDocs. The guides introduce each function where a task needs it.
Design Principles
This module follows Dream’s design principles.
About Dream
This module was originally built for the Dream web toolkit, but it’s completely standalone and can be used in any Gleam project. It follows Dream’s design principles and will be maintained as part of the Dream ecosystem.
Contributing
See the Contributing Guide for guidelines.
License
MIT — see LICENSE.md