Adds an OPTIONS route. Register one only to change the default, which answers with an Allow list of the methods the path
has. The template, handler and max_body work as for get.
choices :: () -> Response {
return with_header(status_only(204), "Allow", "GET, POST");
}
main :: () {
app: App;
defer free_app(*app);
options(*app, "/things", choices);
api := test_client(*app);
response, _ := options(api, "/things");
defer close(*response);
assert(response.status == 204);
allow, found := find_header(response.headers, "allow");
assert(found && allow == "GET, POST");
}Doesn't run in the browser (skipped on wasm).
options :: (
app: *App,
$template: string,
$handler: $H,
max_body := 0,
$loc := #caller_location
)
Adds an OPTIONS route. Register one only to change the default, which answers with an Allow list of the methods the path
has. The template, handler and max_body work as for get.
Parameters
- app: *App
- $template: string
- $handler: $H
- max_body := 0
- $loc := #caller_location
choices :: () -> Response {
return with_header(status_only(204), "Allow", "GET, POST");
}
main :: () {
app: App;
defer free_app(*app);
options(*app, "/things", choices);
api := test_client(*app);
response, _ := options(api, "/things");
defer close(*response);
assert(response.status == 204);
allow, found := find_header(response.headers, "allow");
assert(found && allow == "GET, POST");
}Doesn't run in the browser (skipped on wasm).
options :: (
group: *Group($P),
$template: string,
$handler: $H,
max_body := 0,
$loc := #caller_location
)
The options for a route under a group's prefix.
Parameters
- group: *Group($P)
- $template: string
- $handler: $H
- max_body := 0
- $loc := #caller_location
options :: (
client: *Client,
url: string,
headers: [] Header_Field = .[]
) -> (Client_Response, Client_Error)
OPTIONS: asks what the server allows at url; the Allow header of the response lists the methods.
Parameters
- client: *Client
- url: string
- headers: [] Header_Field