pub struct ModelsDevClient { /* private fields */ }Expand description
Smart HTTP client for the models.dev API with intelligent caching.
This client provides HTTP communication with automatic caching that only updates when the API data has actually changed, using conditional requests.
Implementations§
Source§impl ModelsDevClient
impl ModelsDevClient
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new ModelsDevClient with default settings.
Uses the default API base URL and 30-second timeout.
Sourcepub fn with_base_url(api_base_url: impl Into<String>) -> Self
pub fn with_base_url(api_base_url: impl Into<String>) -> Self
Sourcepub async fn fetch_providers(&self) -> Result<ModelsDevResponse, ModelsDevError>
pub async fn fetch_providers(&self) -> Result<ModelsDevResponse, ModelsDevError>
Fetch providers with smart caching - only updates if API changed.
This method uses conditional HTTP requests to check if the API data has changed before fetching the full response. It combines disk caching with conditional requests for optimal performance.
§Returns
Ok(ModelsDevResponse)- The API response containing providersErr(ModelsDevError)- If the request fails or the response is invalid
§Examples
use models_dev::ModelsDevClient;
let client = ModelsDevClient::new();
let response = client.fetch_providers().await?;
println!("Found {} providers", response.providers.len());Sourcepub fn api_base_url(&self) -> &str
pub fn api_base_url(&self) -> &str
Sourcepub fn clear_cache(&self) -> Result<(), ModelsDevError>
pub fn clear_cache(&self) -> Result<(), ModelsDevError>
Clear cache metadata.
Clears the cache metadata, forcing a fresh API request on next call.
§Examples
use models_dev::ModelsDevClient;
let client = ModelsDevClient::new();
client.clear_cache().unwrap();Sourcepub fn cache_info(&self) -> CacheInfo
pub fn cache_info(&self) -> CacheInfo
Get cache information for debugging.
Returns information about the current cache state.
Trait Implementations§
Source§impl Clone for ModelsDevClient
impl Clone for ModelsDevClient
Source§fn clone(&self) -> ModelsDevClient
fn clone(&self) -> ModelsDevClient
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ModelsDevClient
impl Debug for ModelsDevClient
Auto Trait Implementations§
impl Freeze for ModelsDevClient
impl !RefUnwindSafe for ModelsDevClient
impl Send for ModelsDevClient
impl Sync for ModelsDevClient
impl Unpin for ModelsDevClient
impl !UnwindSafe for ModelsDevClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more