HTTP/1.1 client preview for fastC.
Part of the fastc-core launch set. Implementation ships in the
fastC v1.0 prelude — use http::* works out of the box.
use http::get_status;
// (c: ref(CapNetConnect), host: raw(u8), port: i32, path: raw(u8)) -> i32
get_status opens a TCP connection, sends an HTTP/1.1 GET,
parses the response status code, and closes. Returns the 3-digit
status (200/404/etc.) or -1 on any error.
Every fastC function that reaches the network must declare
c: ref(CapNetConnect). A function without that parameter
structurally cannot call http::get_status — the type system
makes it impossible. The cap can only be minted in main via
caps::init(); library code never fabricates it. The fabrication
check is enforced by the compiler (see fastC's cap_check pass).
use http::get_status;
use caps::init;
use io::println;
use io::print_int;
use io::put_char;
fn main() -> i32 {
let bundle: Caps = init();
let status: i32 = get_status(
addr(bundle.net_connect),
cstr("127.0.0.1"),
8088,
cstr("/"),
);
println(cstr("status:"));
print_int(status);
put_char(10);
return status;
}
| Capability | Status |
|---|---|
| GET request | ✓ |
| Status line parsing | ✓ |
Capability-typed I/O via CapNetConnect |
✓ |
| Body delivery to caller | follow-up |
| Header inspection | follow-up |
| POST / other methods | follow-up |
| HTTP/2 | follow-up |
| TLS | needs fastc-core-tls (deferred) |
| Chunked transfer encoding | follow-up |
| Redirect following | follow-up |
The fastC runtime ships link-compatible stubs for wasm32-wasi
that return -1. Full BSD-socket support follows the
wasi:sockets Preview 2 stabilization.
v0.1.0 — preview. API is final.
MIT