Sample code for 30+ languages & platforms
Rust

Send a REST Request using StringBuilder Bodies

See more REST Examples

Demonstrates Rest.FullRequestSb, which sends a complete request whose text body is read from a StringBuilder and stores the text response body in a second StringBuilder.

Background. Using StringBuilder objects for the request and response bodies avoids extra string conversions, which is helpful when working with large payloads.

Chilkat Rust Downloads

Rust

let rest = chilkat::Rest::new();
let b_tls = true;
let b_auto_reconnect = true;
if rest.connect("example.com", 443, b_tls, b_auto_reconnect).is_err() {
    println!("{}", rest.last_error_text());
    return;
}

// FullRequestSb sends a request whose text body is read from a StringBuilder and stores the text
// response body in a second StringBuilder.  This avoids extra string conversions for large bodies.
let sb_request = chilkat::StringBuilder::new();
let _ = sb_request.append("{ \"query\": \"chilkat\" }");

let _ = rest.add_header("Content-Type", "application/json");

let sb_response = chilkat::StringBuilder::new();
if rest.full_request_sb("POST", "/api/search", &sb_request, &sb_response).is_err() {
    println!("{}", rest.last_error_text());
    return;
}

let Ok(response_text) = sb_response.get_as_string() else {
    println!("{}", sb_response.last_error_text());
    return;
};

println!("{}", response_text);