gossamer πΈοΈ
Cross-runtime JavaScript API bindings for Gleam.
gossamer covers Web Platform APIs (WinterTC) and ECMAScript built-ins that don't have idiomatic Gleam wrappers yet. Bindings work across Node.js, Deno, Bun, and browsers without polyfills β the badges above show the minimum versions verified against gossamer's test suite.
Reach for ecosystem packages first
gossamer is gap-fill. Where the Gleam ecosystem already covers a domain, use its canonical types and functions directly:
| Domain | Use this |
|---|---|
| HTTP requests, responses, methods, headers | gleam_http |
fetch | gleam_fetch |
| URLs (RFC 3986 parsing, building) | gleam/uri |
| Timestamps and durations | gleam_time |
| JSON | gleam_json |
Promise, Array, Symbol | gleam_javascript |
| Iterators | gleam_yielder |
| Regular expressions | gleam_regexp |
| Strong random bytes | gleam_crypto |
gossamer fills the rest: AbortSignal, Blob / File, the Streams API,
SubtleCrypto, WebSocket, Worker / MessageChannel / BroadcastChannel,
Intl formatters, TextDecoder / TextDecoderStream / TextEncoderStream,
CompressionStream / DecompressionStream, URLPattern, BigInt,
Performance / PerformanceObserver, plus per-module extras (fetch_extra,
form_data_extra, time_extra, string_extra, regexp_extra, symbol_extra,
int_extra, float_extra). See the
coverage page for the full list.
Per-binding docs flag cross-runtime gaps where a runtime departs from spec.
Installation
gleam add gossamer gleam_fetch gleam_http gleam_javascript
gossamer's API composes with the canonical ecosystem types, so code using it β
including the example below β typically imports gleam_fetch, gleam_http, and
gleam_javascript directly; add them as direct dependencies alongside gossamer.
Usage
A fetch through gossamer/fetch_extra with cache and keepalive overrides β
chain setters on the FetchOptions builder, then pass it to send. The result
composes with gleam/fetch's body readers:
import gleam/fetch
import gleam/http/request
import gleam/javascript/promise
import gossamer/fetch_extra
pub fn main() {
let assert Ok(req) = request.to("https://example.com/api")
let opts =
fetch_extra.options()
|> fetch_extra.set_cache(fetch_extra.CacheNoStore)
|> fetch_extra.set_keepalive(True)
use resp <- promise.try_await(fetch_extra.send(req, with: opts))
use resp <- promise.try_await(fetch.read_text_body(resp))
promise.resolve(Ok(resp.body))
}
Further documentation lives at https://hexdocs.pm/gossamer.