moonfetch

MoonBit · HTTP client

moonfetch

One call for a request, a client that keeps its connections, and the same program in a browser. HTTP/1.1, HTTP/2 and HTTP/3, chosen by the connection itself.

scroll — the thread follows

01What it is

An HTTP and WebSocket client for MoonBit, written for the way a program actually uses one: a request now and then, a connection kept for the rest, and a body too large to hold.

01Versions HTTP/1.1 and HTTP/2 by ALPN over TLS, HTTP/1.1 in the clear, HTTP/2 in the clear with h2c, and HTTP/3 over QUIC when asked for.
02Hosts Native and wasm over MoonBit's own sockets; the browser and Node over the host's fetch, behind the same Client.
03Connections Idle HTTP/1.1 connections kept per origin; one HTTP/2 or HTTP/3 connection per origin carrying every request to it, many at once.
04Bodies One Body value — text, bytes, JSON, a form, a multipart, or a source produced while the request goes out — so a request cannot carry two.
05Streaming Client::stream returns once the head is in; next hands over the octets as they arrive, for event feeds and downloads.
06Rules Ten redirects, a 303 turning into a GET, credentials kept with their origin, five seconds by default, and no switch that turns certificate checking off.

02The request, before the wire

Three lines of MoonBit on the left; on the right, the octets they become — written by this library, in this page, just now.

let client = @moonfetch.Client::new(timeout=Some(5000))
let page = client.get("https://example.com/a?b=1")
println(page.status)

The client adds what a request must carry and nothing else reports: the host, the user agent, the fields it accepts.

What goes out
the engine loads with the page…

The rest — frames, a live answer, a game about head-of-line blocking — is on the ShowCase.

03On the shelf

aVersion 0.2.0, published on MoonCakes
bPublic items 52 across two packages, listed in the reference
cBackends native, wasm and js; the sockets it stands on have no wasm-gc half
dSpecifications RFC 9110 · 9112 · 9113 · 9114 · 6455 · 6265bis · 1928 · 7578

04Where to go