Rust SDK
serpcheap क्रेट आधिकारिक Rust क्लाइंट है — rustls TLS (कोई सिस्टम OpenSSL नहीं), डिफ़ॉल्ट रूप से एक
सिंक्रोनस blocking क्लाइंट।
इंस्टॉल करें
Section titled “इंस्टॉल करें”cargo add serpcheapक्विकस्टार्ट
Section titled “क्विकस्टार्ट”use serpcheap::{Client, SearchParams};
fn main() -> Result<(), serpcheap::Error> { let client = Client::builder("YOUR_API_KEY").build()?; let resp = client.search(&SearchParams::new("best running shoes").gl("us"))?;
println!("query: {}", resp.search); for r in &resp.organic { println!("{}. {} — {}", r.position, r.title, r.link); } if let Some(stats) = &resp.stats { println!("balance: {} (cost {})", stats.balance, stats.cost); } Ok(())}पैरामीटर और कॉन्फ़िगरेशन
Section titled “पैरामीटर और कॉन्फ़िगरेशन”let params = SearchParams::new("rust language") .gl("gb") // country (default "us") .hl("en") // UI language .tbs("qdr:d") // time filter .page(2); // 1-indexed
use std::time::Duration;use serpcheap::{Client, ClientOptions};
let client = Client::new("YOUR_API_KEY", ClientOptions { base_url: "https://api.serp.cheap".into(), timeout: Duration::from_secs(15), max_retries: 2,})?;त्रुटि प्रबंधन
Section titled “त्रुटि प्रबंधन”use serpcheap::ErrorCode;
match client.search(&SearchParams::new("q")) { Ok(resp) => println!("{} results", resp.organic.len()), Err(err) => match err.code { ErrorCode::InsufficientCredits => eprintln!("top up"), ErrorCode::RateLimited => eprintln!("retry after {:?} ms", err.retry_after_ms), _ if err.is_retryable() => eprintln!("transient: {err}"), _ => eprintln!("error: {err}"), },}