Rust
Simple API connectivity check
ping
pub async fn ping() -> Result<bool>
Result<bool>
true
false
use wacht::api::health::*; if ping().await? { println!("API is reachable"); } else { println!("API is not responding"); }
use wacht::api::health::*; use std::time::Duration; use tokio::time::timeout; // Ping with timeout async fn check_api_connectivity() -> bool { match timeout(Duration::from_secs(5), ping()).await { Ok(Ok(true)) => { println!("✅ API is online"); true } Ok(Ok(false)) => { println!("❌ API returned false"); false } Ok(Err(e)) => { println!("❌ Ping error: {}", e); false } Err(_) => { println!("❌ Ping timeout after 5 seconds"); false } } } // Retry logic async fn ping_with_retry(max_attempts: u32) -> bool { for attempt in 1..=max_attempts { println!("Ping attempt {}/{}", attempt, max_attempts); if ping().await.unwrap_or(false) { return true; } if attempt < max_attempts { tokio::time::sleep(Duration::from_secs(1)).await; } } false }
match ping().await { Ok(true) => println!("API is operational"), Ok(false) => println!("API returned negative response"), Err(e) => println!("Connection error: {}", e), }