Http module

put

procedureextensionexperimental3 overloadsSource

Adds a PUT route; the template, handler and max_body work as for get.

Example
replace :: (id: Path("id", int)) -> string {
    return tprint("replaced %", id.value);
}

main :: () {
    app: App;
    defer free_app(*app);

    put(*app, "/items/{id}", replace);

    api := test_client(*app);

    response, _ := put(api, "/items/3", "new value");
    defer close(*response);

    text, _ := read_text(*response);
    defer free(text);
    assert(text == "replaced 3");
}

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

put :: (
    app: *App,
    $template: string,
    $handler: $H,
    max_body := 0,
    $loc := #caller_location
)

Parameters

app: *App
$template: string
$handler: $H
max_body := 0
$loc := #caller_location
put :: (
    group: *Group($P),
    $template: string,
    $handler: $H,
    max_body := 0,
    $loc := #caller_location
)

The put for a route under a group's prefix.

Parameters

group: *Group($P)
$template: string
$handler: $H
max_body := 0
$loc := #caller_location
put :: (
    client: *Client,
    url: string,
    value: $V,
    headers: [] Header_Field = .[]
) -> (Client_Response, Client_Error)

PUT with value as a JSON body, as post sends it.

Parameters

client: *Client
url: string
value: $V
headers: [] Header_Field = .[]

Returns

Example
Item :: struct {
    name: string;
}

store :: (item: Json(Item)) -> Response {
    return status_only(204);
}

main :: () {
    app: App;
    defer free_app(*app);

    put(*app, "/item", store);

    api := test_client(*app);

    response, _ := put(api, "/item", Item.{ name = "pen" });
    defer close(*response);

    assert(response.status == 204);
}

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

See also