Skip to main content

HttpClient

Trait HttpClient 

Source
pub trait HttpClient: Send + Sync {
    // Required methods
    fn send(&self, request: HttpRequest);
    fn poll(&self) -> Vec<(String, Result<HttpResponse, String>)>;
}
Expand description

Abstract HTTP client.

The engine calls send to initiate a request and poll each frame to collect completed responses. Implementations must not block in either method.

§Object safety

The trait is object-safe so it can be stored as Box<dyn HttpClient>.

§Thread safety

Required to be Send + Sync because the engine state may be shared across threads (e.g. between a main thread and a render thread).

Required Methods§

Source

fn send(&self, request: HttpRequest)

Initiate an HTTP request. Must return immediately.

The implementation should enqueue the request for background execution and make the result available via poll.

Source

fn poll(&self) -> Vec<(String, Result<HttpResponse, String>)>

Collect completed HTTP responses.

Returns (original_url, Result<HttpResponse, error_message>) for every request that has finished since the last call.

Returns an empty Vec when no requests have completed.

Implementors§