pub struct DatadogClient { /* private fields */ }Expand description
HTTP client for Datadog REST APIs.
Implementations§
Source§impl DatadogClient
impl DatadogClient
Sourcepub fn new(base_url: &str, api_key: &str, app_key: &str) -> Result<Self>
pub fn new(base_url: &str, api_key: &str, app_key: &str) -> Result<Self>
Creates a new Datadog API client.
base_url should be the full API host, e.g. https://api.datadoghq.com.
For production use, construct via Self::from_credentials; tests
pass a wiremock URL directly.
Sourcepub fn from_credentials(creds: &DatadogCredentials) -> Result<Self>
pub fn from_credentials(creds: &DatadogCredentials) -> Result<Self>
Creates a client from stored credentials.
Respects DATADOG_API_URL as an optional override: when set in the
process environment it replaces the site-derived base URL. Used for
tests (wiremock) and on-prem Datadog installs.
Sourcepub async fn get_json(&self, url: &str) -> Result<Response>
pub async fn get_json(&self, url: &str) -> Result<Response>
Sends an authenticated GET request and returns the raw response.
Sourcepub async fn post_json<T: Serialize + Sync + ?Sized>(
&self,
url: &str,
body: &T,
) -> Result<Response>
pub async fn post_json<T: Serialize + Sync + ?Sized>( &self, url: &str, body: &T, ) -> Result<Response>
Sends an authenticated POST request with a JSON body and returns the raw response.
Sourcepub async fn response_to_error(response: Response) -> DatadogError
pub async fn response_to_error(response: Response) -> DatadogError
Consumes a non-success response and turns it into a DatadogError.
For 429 responses, appends a human-readable rate-limit summary
(extracted from X-RateLimit-* headers) to the body, so the caller
sees why the retry loop gave up.