Manuscript Documentation
v2026.12.0

@std/net/fetch.ms#

Import each required symbol with import Name from "@std/net/fetch.ms".

FetchBody Enum#

The request body: empty, text, raw bytes, or JSON text; fetch derives a default Content-Type from the case.

Manuscript
enum FetchBody {
    Empty
    Text(value String)
    Raw(value Bytes)
    JsonText(value String)
}

FetchBody.Empty#

Sends no body and no default Content-Type.

Manuscript
Empty

FetchBody.JsonText#

JSON text produced by json_body.

Manuscript
JsonText(value String)

FetchBody.Raw#

Raw bytes, sent as application/octet-stream unless a Content-Type is given.

Manuscript
Raw(value Bytes)

FetchBody.Text#

UTF-8 text, sent as text/plain; charset=utf-8 unless a Content-Type is given.

Manuscript
Text(value String)

FetchBody.JsonText.value#

The encoded JSON text, sent as UTF-8 bytes.

Manuscript
value String

FetchBody.Raw.value#

The bytes, sent unchanged; the value is cloned per request.

Manuscript
value Bytes

FetchBody.Text.value#

The text, sent as UTF-8 bytes.

Manuscript
value String

FetchOptions Type#

Per-request settings. Every field has a default, so FetchOptions() (the default) is a plain GET with a 30 second deadline and a 16 MiB response cap; set only the fields that differ, as in FetchOptions(method: HttpMethod.Post).

Manuscript
type FetchOptions {
    method HttpMethod = HttpMethod.Get
    headers HttpHeaders? = null
    body FetchBody = FetchBody.Empty
    timeout Duration? = seconds(30)
    max_response_bytes Int? = 16777216
}

FetchOptions.body#

The request body; defaults to Empty. A Text, Raw, or JSON body adds a Content-Type only when headers lacks one.

Manuscript
body FetchBody = FetchBody.Empty

FetchOptions.headers#

Extra request headers; null sends no extra fields. The caller’s headers are never modified.

Manuscript
headers HttpHeaders? = null

FetchOptions.max_response_bytes#

Largest accepted response body in bytes; null sets no cap. Larger bodies return EOVERFLOW.

Manuscript
max_response_bytes Int? = 16777216

FetchOptions.method#

The request method; defaults to Get. Extension tokens use the Custom case.

Manuscript
method HttpMethod = HttpMethod.Get

FetchOptions.timeout#

Whole-exchange deadline; null waits without limit.

Manuscript
timeout Duration? = seconds(30)

FetchResponse Type#

A buffered response. Error statuses are ordinary responses; use check_status to reject them.

Manuscript
type FetchResponse {
    head HttpResponseMetadata
    body Bytes
}

FetchResponse.body#

The complete body, within the request’s max_response_bytes.

Manuscript
body Bytes

FetchResponse.head#

Status, headers, and protocol.

Manuscript
head HttpResponseMetadata

FetchResponse.check_status#

Succeeds when the status is 200 through 299. Otherwise returns an Error of kind EIO whose details hold the status, so response.check_status()? rejects error responses.

Manuscript
fn check_status() Result[Void, Error]

FetchResponse.json#

Decodes the body as JSON into T, as in response.json[User]()?; use JsonValue for untyped data.

Manuscript
fn json[T Data](ignore_unknown_fields Bool = true) Result[T, Error]

FetchResponse.ok#

Returns whether the status is 200 through 299.

Manuscript
fn ok() Bool

FetchResponse.text#

Decodes the body as UTF-8.

Manuscript
fn text() Result[String, Error]

Fetcher Type#

A reusable client with connection pooling. Bind it to a local and its scope closes it, or call close yourself.

Manuscript
opaque type Fetcher {
}

Fetcher.close#

Cancels in-flight requests and drops pooled connections; later calls return EBADF.

Manuscript
move fn close() Result[Void, Error]

Fetcher.fetch#

Starts the request and returns a promise of the response, whose body is buffered. A Raw or Text body is resent on redirects that keep it. Requests started together are in flight together.

Manuscript
fn fetch(url String, options FetchOptions = FetchOptions()) Promise[FetchResponse]

Fetcher.stream#

Sends the request and returns the response with its body as a stream. The default options.timeout is a whole-exchange deadline, so set it to null for long streams.

Manuscript
fn stream(url String, options FetchOptions = FetchOptions()) Result[StreamingResponse, Error]

FetcherOptions Type#

Settings fixed when a Fetcher is created.

Manuscript
type FetcherOptions {
    max_redirects Int? = 20
    decompress Bool = true
    cookies Bool = false
    tls TlsOptions = TlsOptions(
		server_name: "",
		roots_pem: "",
		certificate_pem: "",
		private_key_pem: "",
		alpn: [],
		require_client_certificate: false,
	)
}

FetcherOptions.cookies#

Keep an in-memory cookie jar for the fetcher’s lifetime.

Manuscript
cookies Bool = false

FetcherOptions.decompress#

Decode gzip responses, bounded by max_response_bytes.

Manuscript
decompress Bool = true

FetcherOptions.max_redirects#

Most redirects followed per request; 0 returns the redirect itself and null sets no cap.

Manuscript
max_redirects Int? = 20

FetcherOptions.tls#

TLS trust and client-certificate settings; add h2 to alpn to allow HTTP/2.

Manuscript
tls TlsOptions = TlsOptions(
		server_name: "",
		roots_pem: "",
		certificate_pem: "",
		private_key_pem: "",
		alpn: [],
		require_client_certificate: false,
	)

fetch Function#

Starts one buffered request on a one-shot client and returns its promise; requests started together are in flight together. By default it follows up to 20 redirects, limits the body to 16 MiB, and limits the exchange to 30 seconds. Set FetchOptions fields to change the body and time limits; for the redirect limit and other client settings, use a Fetcher.

Manuscript
fn fetch(url String, options FetchOptions = FetchOptions()) Promise[FetchResponse] { ... }

fetcher Function#

Creates a reusable fetcher on net, whose restrictions apply to every request and redirect; null uses the host network.

Manuscript
fn fetcher(options FetcherOptions = FetcherOptions(), net Network? = null) Result[Fetcher, Error] { ... }

json_body Function#

Encodes value as a JSON request body, sent as application/json unless a Content-Type is given.

Manuscript
fn json_body[T Data](value T) Result[FetchBody, Error] { ... }