pub struct DatadogClient { /* private fields */ }Expand description
HTTP client for interacting with the Datadog API.
Handles authentication, request building, and response parsing for all Datadog API endpoints. Includes client-side rate limiting to prevent hitting Datadog’s API limits.
Implementations§
Source§impl DatadogClient
impl DatadogClient
Sourcepub fn new(config: DatadogConfig) -> Result<Self>
pub fn new(config: DatadogConfig) -> Result<Self>
Creates a new Datadog API client with the given configuration.
§Errors
Returns an error if the HTTP client cannot be built.
Sourcepub fn with_rate_limit(
config: DatadogConfig,
rate_limit_config: RateLimitConfig,
) -> Result<Self>
pub fn with_rate_limit( config: DatadogConfig, rate_limit_config: RateLimitConfig, ) -> Result<Self>
Creates a new Datadog API client with custom rate limiting configuration.
§Errors
Returns an error if the HTTP client cannot be built.
Sourcepub fn config(&self) -> &DatadogConfig
pub fn config(&self) -> &DatadogConfig
Returns a reference to the configuration used by this client.
pub async fn get<T: DeserializeOwned>(&self, endpoint: &str) -> Result<T>
pub async fn get_with_query<T: DeserializeOwned, Q: Serialize>( &self, endpoint: &str, query: &Q, ) -> Result<T>
pub async fn post<T: DeserializeOwned, B: Serialize>( &self, endpoint: &str, body: &B, ) -> Result<T>
pub async fn put<T: DeserializeOwned, B: Serialize>( &self, endpoint: &str, body: &B, ) -> Result<T>
pub async fn delete(&self, endpoint: &str) -> Result<()>
pub async fn delete_with_response<T: DeserializeOwned>( &self, endpoint: &str, ) -> Result<T>
Sourcepub fn rate_limiter(&self) -> &RateLimiter
pub fn rate_limiter(&self) -> &RateLimiter
Returns a reference to the rate limiter (for monitoring)
Sourcepub async fn get_cached<T: DeserializeOwned>(
&self,
endpoint: &str,
cache_info: Option<&CacheInfo>,
) -> Result<Option<CachedResponse<T>>>
pub async fn get_cached<T: DeserializeOwned>( &self, endpoint: &str, cache_info: Option<&CacheInfo>, ) -> Result<Option<CachedResponse<T>>>
GET request with conditional caching support (ETag/Last-Modified).
Returns Ok(Some(response)) if data was modified, or Ok(None) if
the cached version is still valid (304 Not Modified).
§Arguments
endpoint- API endpointcache_info- Optional cache info from a previous response
§Example
let client = DatadogClient::new(DatadogConfig::from_env()?)?;
// First request - no cache
let response: CachedResponse<serde_json::Value> = client
.get_cached("/api/v1/monitor", None)
.await?
.expect("First request should return data");
// Subsequent request with cache info
match client.get_cached::<serde_json::Value>("/api/v1/monitor", Some(&response.cache_info)).await? {
Some(new_response) => println!("Data was modified"),
None => println!("Data unchanged, use cached version"),
}Trait Implementations§
Source§impl Clone for DatadogClient
impl Clone for DatadogClient
Source§fn clone(&self) -> DatadogClient
fn clone(&self) -> DatadogClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more