std::net::http::http_clientHTTP client compatibility module for outbound requests.
Provides basic outbound HTTP functionality for native Hew programs via
import std::net::http::http_client;.
This compatibility module now carries the bounded v0.3 client slice:
request, request_string, set_timeout, plus the legacy get / post
helpers built on the same request path.
Response accessors: status(), body(), header(name), content_type(),
headers() (all headers as Vec<(string, string)>), and free().
The _string convenience helpers (request_string, get_string,
post_string) return Option<string> โ None on transport failure.
import std::net::http::http_client;
fn main() {
match http_client.get_string("https://example.com") {
Some(body) => println(body),
None => println("request failed"),
}
let headers: Vec<(string, string)> = Vec::new();
headers.push(("Accept", "application/json"));
let resp = http_client.request("GET", "https://api.example.com/data", "", headers);
println(resp.status());
resp.free();
}
requestPerform an HTTP request and return a Response handle.
Each header entry is a (name, value) pair, e.g. ("Accept", "application/json").
let headers: Vec<(string, string)> = Vec::new();
headers.push(("Accept", "application/json"));
let resp = http_client.request("GET", "https://example.com", "", headers);
println(resp.status());
resp.free();
request_stringPerform an HTTP request and return the response body as a string.
Each header entry is a (name, value) pair, e.g. ("Accept", "application/json").
Returns None on transport or network failure. Non-2xx HTTP responses
still return Some (the body may be empty); use http_client.request
to inspect the status code.
let headers: Vec<(string, string)> = Vec::new();
match http_client.request_string("GET", "https://example.com", "", headers) {
Some(body) => println(body),
None => println("request failed"),
}
set_timeoutSet the global timeout applied to subsequent outbound HTTP requests.
Pass 0 to disable the timeout.
last_errorReturn the last HTTP client error observed on this thread.
Accessors that return null on allocation failure update this string. Successful accessor calls clear it.
getPerform an HTTP GET request and return a Response handle.
let resp = http_client.get("https://example.com");
println(resp.status());
resp.free();
postPerform an HTTP POST request and return a Response handle.
let resp = http_client.post("https://api.example.com/data", "application/json", "{}");
resp.free();
get_stringPerform an HTTP GET request and return the response body as a string.
This is a convenience function that combines the request and body extraction in a single call.
Returns None on transport or network failure. Non-2xx HTTP responses
still return Some (the body may be empty); use http_client.get
to inspect the status code.
match http_client.get_string("https://example.com") {
Some(body) => println(body),
None => println("request failed"),
}
post_stringPerform an HTTP POST request and return the response body as a string.
Returns None on transport or network failure. Non-2xx HTTP responses
still return Some (the body may be empty); use http_client.post
to inspect the status code.
match http_client.post_string(
"https://api.example.com/submit",
"application/json",
"{\"key\": \"value\"}",
) {
Some(body) => println(body),
None => println("request failed"),
}
ResponseAn opaque HTTP response handle.
Obtained from http_client.request(...), http_client.get(...), or
http_client.post(...). Must be freed with free() when no longer needed.
ResponseMethodsMethods available on an HTTP Response.
Return the HTTP status code (e.g. 200, 404). Returns -1 on error.
Return a copy of the response body as a string.
Look up a response header by name (case-insensitive).
Returns an empty string if the header is not present.
Return the Content-Type response header.
Returns an empty string if not present.
Return all response headers as a list of (name, value) pairs.
The returned vector is owned by the caller; Hew frees it automatically when it goes out of scope. Returns an empty vector if no headers were captured or the response is invalid.
Release the response resources.