Sample code for 30+ languages & platforms
Rust

Clear REST Authentication Settings

See more REST Examples

Demonstrates Rest.ClearAuth, which removes any authentication providers and credentials previously configured through the SetAuth* methods.

Background. Clearing authentication is useful when reusing a Rest object for a request that must be sent without credentials, or before switching to a different authentication method.

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

// 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 username = "myUsername".to_string();
let password = "myPassword".to_string();
if rest.set_auth_basic(&username, &password).is_err() {
    println!("{}", rest.last_error_text());
    return;
}

// ClearAuth removes any authentication providers and credentials previously configured through the
// SetAuth* methods, for example before reusing the object for an unauthenticated request.
let _ = rest.clear_auth();

println!("Authentication cleared.");