Expand description
HTTP client module providing the main SerpAPI client implementation.
This module contains the SerpClient
struct which is the primary
interface for interacting with the SerpAPI service. It provides methods for executing
searches, handling retries, and managing HTTP connections efficiently.
§Examples
use serp_sdk::client::SerpClient;
let client = SerpClient::builder()
.api_key("your-api-key")
.build()
.expect("Failed to create client");
§SerpAPI HTTP Client Module
This module provides the core HTTP client implementation for interacting with the SerpAPI service. It handles all aspects of API communication including authentication, request construction, response parsing, error handling, and retry logic with exponential backoff.
§Architecture
The client module follows a builder pattern for configuration and uses async/await for
non-blocking I/O operations. It’s built on top of reqwest
for HTTP communication and
integrates with tracing
for observability.
§Key Components
SerpClient
: The main client struct that manages API interactionsSerpClientBuilder
: A fluent builder for configuring client instances- Retry logic with configurable policies for handling transient failures
- Automatic rate limiting detection and handling
§Examples
§Basic Usage
use serp_sdk::{SerpClient, SearchQuery};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a client with an API key
let client = SerpClient::new("your-api-key")?;
// Execute a search
let results = client.search(
SearchQuery::new("rust programming")
).await?;
Ok(())
}
§Advanced Configuration
use serp_sdk::{SerpClient, RetryPolicy};
use std::time::Duration;
let client = SerpClient::builder()
.api_key("your-api-key")
.timeout(Duration::from_secs(60))
.retry_policy(
RetryPolicy::new(5)
.with_base_delay(Duration::from_millis(100))
)
.user_agent("my-app/1.0")
.base_url("https://custom-proxy.example.com")
.build()?;
Structs§
- Serp
Client - The main SerpAPI client for executing search requests.
- Serp
Client Builder - A builder for constructing
SerpClient
instances with custom configuration.