Ricky Moony and Lucy, a moon shaped mascot for Dream with the star shaped mascot for Gleam, each with cute cartoon eyes and a smile

Type-safe HTTP client for Gleam with streaming support


Hex Package Latest Release HexDocs Coverage MIT License Gleam

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

FeatureWhat you get
Four execution modesBlocking, yielder streaming, process-based, and actor messages
OTP-first designProcess-based streams work well with OTP
Recording/playbackRecord HTTP calls for tests, debug production, work offline
Type-safeResult types force error handling, with no silent failures
HTTP/2 readyNative HTTP/2 multiplexing via gun for high concurrency
Framework-independentZero dependencies on Dream or other frameworks
Concurrent streamsHandle multiple HTTP streams in a single actor
Stream cancellationCancel in-flight requests cleanly
Builder patternConsistent, 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 Tested snippet Guide: Getting started

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

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


Built in Gleam, on the BEAM, by the Dream Team ❤️
✨ Search Document