Rust
Rust
Simple GET using REST
See more REST Examples
Demonstrates how to do a simple HTTP GET request using REST.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let rest = chilkat::Rest::new();
// Connect to the REST server.
let b_tls = true;
let port = 443;
let b_auto_reconnect = true;
let _ = rest.connect("my-store.com", port, b_tls, b_auto_reconnect).is_ok();
let Ok(mut response_json) = rest.full_request_no_body("GET", "/wp-json/wc/v1/products?consumer_key=YOUR_CONSUMER_KEY&consumer_secret=YOUR_CONSUMER_SECRET") else {
println!("{}", rest.last_error_text());
return;
};
println!("{}", response_json);
println!("----");
// We can alternatively do this:
let _ = rest.clear_all_query_params();
let _ = rest.add_query_param("consumer_key", "YOUR_CONSUMER_KEY");
let _ = rest.add_query_param("consumer_secret", "YOUR_CONSUMER_SECRET");
response_json = rest.full_request_no_body("GET", "/wp-json/wc/v1/products").unwrap_or_default();
if !rest.last_method_success() {
println!("{}", rest.last_error_text());
return;
}
println!("{}", response_json);