Manuscript Documentation
v2026.12.0

HTTP requests#

Make an HTTP GET request and read the response. Each program is a complete .ms file: save it under the shown name and run the command from that directory (getting started ). main returns the exit status.

Make an HTTP GET request#

Save as get.ms. fetch buffers the body, check_status() rejects statuses outside 200–299, and text() decodes UTF-8.

Manuscript
import (
    stdout from "@std/io/io.ms",
    FetchOptions, fetch from "@std/net/fetch.ms",
    arguments from "@std/os/env.ms",
)

fn run() Result[Void, Error] {
    url := ok_or(arguments().first(), Error("missing URL", kind: "EINVAL"))?
    response := fetch(url, FetchOptions(max_response_bytes: 1048576)).wait()?
    response.check_status()?

    text := response.text()?
    stdout().write(text)?
    return stdout().flush()
}

fn main() Void! {
    return run()
}
sh
# In another terminal, serve notes.txt from the current directory:
python3 -m http.server 8000 --bind 127.0.0.1

# In your program's terminal:
ms run get.ms -- http://127.0.0.1:8000/notes.txt

The program prints the contents served from notes.txt:

text
hello from a file

The server needs Python 3 and a notes.txt (from the file-reading recipe). Transport failures, non-success statuses, and invalid UTF-8 exit 1; the body is capped at 1 MiB. Other FetchOptions fields keep their defaults, including the 30-second deadline.

For a JSON response, response.json[Config]()? decodes the body into a type you define, here a Config of your own. Call check_status() first when an error status should fail the operation: fetch itself returns error statuses as ordinary responses. For repeated requests, bind a pooled Fetcher with client := fetcher()?; see the fetch API .

To answer requests instead, see serving HTTP .