# curl-wasm A `curl` clone implemented **100% in plain WebAssembly Text format (`curl.wat`)**, targeting the **WASI 0.2 Component Model** (`wasi:cli`, `wasi:io`, `wasi:clocks`, `wasi:filesystem`, `wasi:http`). There is no Rust, C, Go, or JavaScript anywhere in the implementation — `curl.wat` assembles directly into a standalone WASI 0.2 component (`curl.wasm`) with `wasm-tools` and executes HTTP and HTTPS (TLS) transfers via `wasmtime`. ## Build & Run Prerequisites: - `wasm-tools` - `wasmtime` (with WASI 0.2 / `wasi:http` support) ```sh make build ./curl-wasm https://example.com ``` Or run `curl.wasm` directly with `wasmtime` (note the `--` so `wasmtime` does not intercept flags like `-O`, `-D`, `-h`, or `-V`): ```sh wasmtime run -S http --dir=. -- ./curl.wasm -fsSI https://example.com ``` Run the test suite: ```sh make test ``` ## Compile to Native (`wasm2c`) You can also compile `curl.wasm` into a standalone native binary (`./curl-native`, backed by POSIX sockets and OpenSSL) using `wasm2c` via `just`: ```sh just native just run-native -fsSI https://example.com just test-native ``` ## Supported Options | Option | Description | | --- | --- | | `-h`, `--help` | Show usage help and exit | | `-V`, `--version` | Show version/protocols and exit | | `-X`, `--request ` | Custom HTTP method (`GET`, `POST`, `PATCH`, `DELETE`, custom verbs) | | `-H`, `--header
` | Add/override header (`Name: Value`), suppress (`Name:`), or send empty (`Name;`) | | `-d`, `--data`, `--data-ascii ` | Send request body (default `POST`, `@file` / `@-` strips CR/LF) | | `--data-raw ` | Send literal request body (`@` not treated as file) | | `--data-binary ` | Send raw binary body (`@file` / `@-` preserves bytes) | | `--data-urlencode ` | URL-encode data (`content`, `=content`, `name=content`, `@file`, `name@file`) | | `-G`, `--get` | Append `-d` data to URL query string and use `GET` | | `-T`, `--upload-file ` | Upload local file (or `-` for stdin) via `PUT` | | `-i`, `--include` | Include response status line and headers in output | | `-I`, `--head` | Fetch headers only (`HEAD` request) | | `-L`, `--location` | Follow `301`/`302`/`303`/`307`/`308` redirects | | `--max-redirs ` | Maximum redirects allowed (default `50`, `-1` unlimited) | | `-o`, `--output ` | Write body to `` (`-` for stdout, `/dev/null` discard sink) | | `-O`, `--remote-name` | Write output to local file named from remote URL path | | `-D`, `--dump-header ` | Write response headers to `` (or `-` for stdout) | | `-s`, `--silent` | Silent mode (suppress error messages) | | `-S`, `--show-error` | Show errors even when `-s` is enabled | | `-v`, `--verbose` | Print `*` info, `>` request headers, and `<` response headers to stderr | | `-f`, `--fail` | Fail silently (exit non-zero, no body/file written) on HTTP status >= 400 | | `-u`, `--user ` | Send `Authorization: Basic ...` header | | `-A`, `--user-agent ` | Set custom `User-Agent` | | `-e`, `--referer ` | Set `Referer` header | | `-b`, `--cookie ` | Set `Cookie` header | | `-r`, `--range ` | Set `Range: bytes=` header | | `-w`, `--write-out ` | Print transfer stats template after completion | | `--connect-timeout ` | Connection timeout in seconds | | `-m`, `--max-time ` | Total transfer timeout in seconds | | `--` | End of options | ### `--write-out` Variables `%{http_code}`, `%{response_code}`, `%{size_download}`, `%{size_upload}`, `%{time_total}`, `%{url_effective}`, `%{content_type}`, `%{redirect_url}`, `%{num_redirects}`, `%{scheme}`, `%{method}`, `\n`, `\r`, `\t`, `\\`, `%%`.