Sends request and returns once the status line and headers have arrived. The response is
whatever the server answered (a 404 is a response, not an error); the body is read from it with
read_text, read_bytes, read_json or read_some. Errors are only about not getting a
response: the URL, the connection, a timeout, a reply that is not HTTP, too many redirects.
echo :: (body: *Body) -> string {
data, _ := read_all(body);
return cast(string) data;
}
main :: () {
app: App;
defer free_app(*app);
post(*app, "/echo", echo);
api := test_client(*app);
response, error := send(api, .{ method = .POST, url = "/echo", body = bytes_of("ping") });
assert(error.kind == .NONE);
defer close(*response);
text, _ := read_text(*response);
defer free(text);
assert(text == "ping");
}Doesn't run in the browser (skipped on wasm).
send :: (
client: *Client,
request: Client_Request
) -> (Client_Response, Client_Error)
Parameters
- client: *Client
- request: Client_Request