Sample code for 30+ languages & platforms
Rust

REST Auto Reconnect for Multiple Requests (dev.markitondemand.com)

See more REST Examples

Demonstrates how the autoReconnect argument to the Connect method is used.

Chilkat Rust Downloads

Rust

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

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

// This example demonstrates the usage of the autoReconnect argument to the Connect method.
// When autoReconnect is on, subsequent REST method calls will automatically re-connect
// if necessary, using the same information (domain/IP address, port number, and TLS).
let b_tls = false;
let port = 80;
let b_auto_reconnect = true;
let _ = rest.connect("dev.markitondemand.com", port, b_tls, b_auto_reconnect).is_ok();

// Get a stock quote:
let _ = rest.add_query_param("symbol", "AAPL").is_ok();
let Ok(mut response_xml) = rest.full_request_no_body("GET", "/MODApis/Api/v2/Quote") else {
    println!("{}", rest.last_error_text());
    return;
};

let xml = chilkat::Xml::new();
let _ = xml.load_xml(&response_xml).is_ok();
println!("AAPL LastPrice: {}", xml.get_child_content("LastPrice").unwrap_or_default());

// Get another stock quote.  If a new HTTP connection is required,
// the REST object will automatically connect using the same parameters.
let _ = rest.add_query_param("symbol", "AMZN").is_ok();
response_xml = rest.full_request_no_body("GET", "/MODApis/Api/v2/Quote").unwrap_or_default();
if !rest.last_method_success() {
    println!("{}", rest.last_error_text());
    return;
}

let _ = xml.load_xml(&response_xml).is_ok();
println!("AMZN LastPrice: {}", xml.get_child_content("LastPrice").unwrap_or_default());