Sample code for 30+ languages & platforms
Rust

Use an Existing Socket Connection for REST

See more REST Examples

Demonstrates Rest.UseConnection, which supplies an already-connected Socket as the transport for REST requests instead of calling Connect. This is useful when the connection must be established with specific socket options or shared across objects.

Background. Rest can operate over any connected socket. The second argument enables automatic reconnection so a dropped connection is transparently re-established between requests.

Chilkat Rust Downloads

Rust

// Demonstrates supplying an already-connected socket for the REST transport.  This is useful when
// the connection must be established with specific socket options, or reused across objects.

let socket = chilkat::Socket::new();
let b_ssl = true;
if socket.connect("example.com", 443, b_ssl, 5000).is_err() {
    println!("{}", socket.last_error_text());
    return;
}

let rest = chilkat::Rest::new();

// Use the connected socket as the transport.  The 2nd argument enables automatic reconnection.
let b_auto_reconnect = true;
if rest.use_connection(&socket, b_auto_reconnect).is_err() {
    println!("{}", rest.last_error_text());
    return;
}

let Ok(response_text) = rest.full_request_no_body("GET", "/api/status") else {
    println!("{}", rest.last_error_text());
    return;
};

println!("{}", response_text);