use reqres::Client;
use std::time::Duration;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("=== reqres v0.4.0 HTTPS Client Demo ===\n");
let client = Client::builder()
.timeout(Duration::from_secs(30))
.follow_redirects(true)
.max_redirects(5)
.user_agent("reqres/0.2.0 (HTTPS Demo)")
.build()?;
println!("Sending HTTPS GET request to httpbin.org...");
match client.get("https://httpbin.org/get").await {
Ok(response) => {
println!("✓ HTTPS GET request successful!");
println!(" Status: {} {}", response.status(), response.status_text);
println!(" Headers:");
for (key, value) in &response.headers {
println!(" {}: {}", key, value);
}
println!("\n Body preview (first 500 chars):");
let body_text = response.text().unwrap_or_default();
let body_preview = if body_text.len() > 500 {
&body_text[..500]
} else {
&body_text
};
println!("{}", body_preview);
}
Err(e) => {
eprintln!("✗ HTTPS GET request failed: {}", e);
}
}
println!("\n{}\n", &"=".repeat(50));
println!("Testing redirect handling...");
match client.get("https://httpbin.org/redirect/3").await {
Ok(response) => {
println!("✓ Redirect handled successfully!");
println!(" Final Status: {}", response.status());
}
Err(e) => {
eprintln!("✗ Redirect test failed: {}", e);
}
}
println!("\n=== Demo completed ===");
Ok(())
}