pub trait RequestHandler {
// Required method
fn send_request(
&self,
url: Url,
method: &str,
data: Option<HashMap<&str, &str>>,
) -> impl Future<Output = Result<Response>> + Send;
}
Expand description
Async trait for handling HTTP requests across different platforms
This trait provides a platform-agnostic interface for making HTTP requests. Implementations handle the specifics of each platform (native vs WASM) while providing a consistent API for the rest of the library.
§Platform Implementations
- Native: Uses
reqwest
for full HTTP client functionality - WASM: Uses
fetch
API for browser-compatible requests
§Example
use kiteconnect_async_wasm::connect::utils::RequestHandler;
use std::collections::HashMap;
let client = MyClient;
let url = reqwest::Url::parse("https://api.example.com/data")?;
let mut params = HashMap::new();
params.insert("key", "value");
let response = client.send_request(url, "GET", Some(params)).await?;
Required Methods§
Sourcefn send_request(
&self,
url: Url,
method: &str,
data: Option<HashMap<&str, &str>>,
) -> impl Future<Output = Result<Response>> + Send
fn send_request( &self, url: Url, method: &str, data: Option<HashMap<&str, &str>>, ) -> impl Future<Output = Result<Response>> + Send
Send an HTTP request with the specified parameters
§Arguments
url
- The complete URL to send the request tomethod
- HTTP method (“GET”, “POST”, “PUT”, “DELETE”)data
- Optional form data to include in the request
§Returns
A Result
containing the HTTP response or an error
§Errors
Returns an error if:
- The network request fails
- The URL is malformed
- Authentication is required but missing
- The server returns an error status
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§
impl RequestHandler for KiteConnect
Implement the async request handler for KiteConnect struct