Sample code for 30+ languages & platforms
Rust

Configure HTTP Basic Authentication with SecureString

See more REST Examples

Demonstrates Rest.SetAuthBasicSecure, which configures HTTP Basic authentication using SecureString objects instead of plaintext strings.

Background. A SecureString keeps sensitive values encrypted in memory, reducing the window in which credentials appear as readable plaintext. This is otherwise equivalent to SetAuthBasic.

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;
}

// SetAuthBasicSecure configures HTTP Basic authentication using SecureString objects, which keep
// the credentials encrypted in memory.
// Normally you would not hard-code secrets in source.  You should instead obtain them from an
// interactive prompt, environment variable, or a secrets vault.
let ss_username = chilkat::SecureString::new();
let _ = ss_username.append("myUsername");
let ss_password = chilkat::SecureString::new();
let _ = ss_password.append("myPassword");

if rest.set_auth_basic_secure(&ss_username, &ss_password).is_err() {
    println!("{}", rest.last_error_text());
    return;
}

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

println!("{}", response_text);