Http module

start

procedureextensionexperimentalSource

Starts listening on the running scheduler (call it inside Io.io_run, from a fiber) and returns at once; connections are served by fibers of this scheduler. Fails if the address cannot be bound, the routes conflict or config.tls is not usable. stop and wait end it.

Example
Io :: #import "Extensions/Io";

app: App;

hello :: () -> string {
    return "hello";
}

main :: () {
    get(*app, "/hello", hello);
    app.config.address = "127.0.0.1:0"; // any free port

    Io.io_run(() {
        server, error := start(*app);
        assert(error.kind == .NONE);

        client: Client;
        response, _ := get(*client, tprint("%/hello", server_url(server)));
        text, _ := read_text(*response);
        assert(text == "hello");
        close(*response);

        stop(server);
        wait(server);
    });
}

Doesn't run in the browser (skipped on wasm).

start :: (app: *App, reuse_port := false) -> (*Server, Serve_Error)

Parameters

app: *App
reuse_port := false

Returns

See also