use dotenvy::dotenv;
use kode_bridge::{ClientConfig, IpcHttpClient, Result};
use serde_json::Value;
use std::env;
use std::time::Duration;
#[tokio::main]
async fn main() -> Result<()> {
dotenv().ok();
#[cfg(unix)]
let ipc_path = env::var("CUSTOM_SOCK").unwrap_or_else(|_| "/tmp/example.sock".to_string());
#[cfg(windows)]
let ipc_path = env::var("CUSTOM_PIPE").unwrap_or_else(|_| r"\\.\pipe\example".to_string());
println!("📡 Large Data Request Example");
println!("Connecting to: {}", ipc_path);
let config = ClientConfig {
default_timeout: Duration::from_secs(30), enable_pooling: true,
pool_config: kode_bridge::pool::PoolConfig {
max_size: 5,
min_idle: 2,
max_idle_time_ms: 300_000,
..Default::default()
},
max_retries: 2,
retry_delay: Duration::from_millis(500),
..Default::default()
};
let client = IpcHttpClient::with_config(&ipc_path, config)?;
println!("🔄 Sending request to /proxies endpoint...");
let response = client
.get("/proxies")
.timeout(Duration::from_secs(45)) .send()
.await?;
println!("✅ Response received!");
println!("🔍 Response Details:");
println!(" Status: {}", response.status());
println!(" Success: {}", response.is_success());
println!(" Content Length: {} bytes", response.content_length());
match response.json_value() {
Ok(json) => {
if let Value::Array(ref items) = json {
println!("📊 Large Data Stats:");
println!(" Array length: {} items", items.len());
println!(" First item preview: {:#}", items.first().unwrap_or(&Value::Null));
if items.len() > 1 {
println!(" Last item preview: {:#}", items.last().unwrap_or(&Value::Null));
}
} else if let Value::Object(ref obj) = json {
println!("📊 Large Object Stats:");
println!(" Object keys: {} properties", obj.len());
for (key, _) in obj.iter().take(5) {
println!(" - {}", key);
}
if obj.len() > 5 {
println!(" ... and {} more", obj.len() - 5);
}
} else {
println!("📄 JSON Response: {:#}", json);
}
}
Err(e) => {
let raw_body = response.body()?;
println!("📄 Raw Response Length: {} bytes", raw_body.len());
if raw_body.len() > 500 {
println!("📄 Response Preview: {}...", &raw_body[..500]);
} else {
println!("📄 Raw Response: {}", raw_body);
}
println!("⚠️ JSON parse error: {}", e);
}
}
if let Some(stats) = client.pool_stats() {
println!("📊 Connection Pool Stats: {}", stats);
}
drop(client);
Ok(())
}