HttpClient

Trait HttpClient 

Source
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 implements Serialize
  • ApiUrl - The API URL type that can be referenced as a string
  • ApiKey - The API key type that can be referenced as a string

Required Associated Types§

Source

type Body: Serialize

The request body type that must implement JSON serialization.

Source

type ApiUrl: AsRef<str>

The API URL type that must be convertible to a string reference.

Source

type ApiKey: AsRef<str>

The API key type that must be convertible to a string reference.

Required Methods§

Source

fn api_url(&self) -> &Self::ApiUrl

Returns a reference to the API URL.

Source

fn api_key(&self) -> &Self::ApiKey

Returns a reference to the API key for authentication.

Source

fn body(&self) -> &Self::Body

Returns a reference to the request body.

Provided Methods§

Source

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.

Source

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.

Implementors§

Source§

impl HttpClient for CancelBatchRequest

Source§

impl HttpClient for CreateBatchRequest

Source§

impl HttpClient for BatchesListRequest

Source§

impl HttpClient for BatchesRetrieveRequest

Source§

impl HttpClient for FileContentRequest

Source§

impl HttpClient for FileDeleteRequest

Source§

impl HttpClient for FileListRequest

Source§

impl HttpClient for FileUploadRequest

Source§

impl HttpClient for KnowledgeCapacityRequest

Source§

impl HttpClient for CreateKnowledgeRequest

Source§

impl HttpClient for KnowledgeDeleteRequest

Source§

impl HttpClient for DocumentDeleteRequest

Source§

impl HttpClient for DocumentImageListRequest

Source§

impl HttpClient for DocumentListRequest

Source§

impl HttpClient for DocumentReembeddingRequest

Source§

impl HttpClient for DocumentRetrieveRequest

Source§

impl HttpClient for DocumentUploadFileRequest

Source§

impl HttpClient for DocumentUploadUrlRequest

Source§

impl HttpClient for KnowledgeListRequest

Source§

impl HttpClient for KnowledgeRetrieveRequest

Source§

impl HttpClient for KnowledgeUpdateRequest

Source§

impl HttpClient for Moderation

Source§

impl HttpClient for EmbeddingRequest

Source§

impl HttpClient for RerankRequest

Source§

impl HttpClient for TokenizerRequest

Source§

impl HttpClient for VoiceDeleteRequest

Source§

impl HttpClient for VoiceListRequest

Source§

impl HttpClient for WebSearchRequest

Source§

impl<N> HttpClient for AsyncChatGetRequest<N>
where N: ModelName + AsyncChat,

Source§

impl<N> HttpClient for TtsSpeechRequest<N>

Source§

impl<N> HttpClient for AudioTranscriptionRequest<N>
where N: ModelName + AudioToText + Serialize + Clone + Send + Sync + 'static,

Source§

impl<N> HttpClient for ImageGenRequest<N>

Source§

impl<N> HttpClient for VideoGenRequest<N>

Source§

impl<N> HttpClient for VoiceCloneRequest<N>

Source§

impl<N, M, S> HttpClient for AsyncChatCompletion<N, M, S>

Source§

type Body = ChatBody<N, M>

Source§

type ApiUrl = &'static str

Source§

type ApiKey = String

Source§

impl<N, M, S> HttpClient for ChatCompletion<N, M, S>