pub trait HttpClient {
type Body: Serialize;
type ApiUrl: AsRef<str>;
type ApiKey: AsRef<str>;
// Required methods
fn api_url(&self) -> &Self::ApiUrl;
fn api_key(&self) -> &Self::ApiKey;
fn body(&self) -> &Self::Body;
// Provided methods
fn post(&self) -> impl Future<Output = Result<Response>> + Send { ... }
fn get(&self) -> impl Future<Output = Result<Response>> + Send { ... }
}Expand description
Trait for HTTP clients that communicate with the Zhipu AI API.
This trait provides a standardized interface for making HTTP requests to Zhipu AI API endpoints with proper authentication and error handling.
§Type Parameters
Body- The request body type that implementsSerializeApiUrl- The API URL type that can be referenced as a stringApiKey- The API key type that can be referenced as a string
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn post(&self) -> impl Future<Output = Result<Response>> + Send
fn post(&self) -> impl Future<Output = Result<Response>> + Send
Sends a POST request to the API endpoint.
This method handles:
- JSON serialization of the request body
- Bearer token authentication
- Error response parsing and reporting
- Connection reuse through the shared HTTP client
Returns the HTTP response on success, or an error on failure.
Sourcefn get(&self) -> impl Future<Output = Result<Response>> + Send
fn get(&self) -> impl Future<Output = Result<Response>> + Send
Sends a GET request to the API endpoint.
This method is used for endpoints that don’t require a request body.
It handles authentication and error response parsing similar to post().
Returns the HTTP response on success, or an error on failure.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.