pub struct HttpClient {}Expand description
An HTTP client interface for asynchronous HTTP requests.
All requests run on background threads and return a request id that can be used with cancel() or isRequestActive().
Completion and progress callbacks are dispatched back to the logic thread.
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub fn post_async(
url: &str,
json: &str,
timeout: f32,
callback: Box<dyn FnMut(Option<String>)>,
) -> i64
pub fn post_async( url: &str, json: &str, timeout: f32, callback: Box<dyn FnMut(Option<String>)>, ) -> i64
Sends a POST request with a JSON body.
§Arguments
url- The URL to send the request to.json- The JSON data to send in the request body.timeout- The timeout in seconds for the request.callback- A callback function invoked when the request finishes. It receives the response body, ornilif the request fails or is cancelled.
§Returns
uint64_t- The request id. Returns0when the request cannot be scheduled.
Sourcepub fn post_with_headers_async(
url: &str,
headers: &Vec<&str>,
json: &str,
timeout: f32,
callback: Box<dyn FnMut(Option<String>)>,
) -> i64
pub fn post_with_headers_async( url: &str, headers: &Vec<&str>, json: &str, timeout: f32, callback: Box<dyn FnMut(Option<String>)>, ) -> i64
Sends a POST request with custom headers and a JSON body.
§Arguments
url- The URL to send the request to.headers- A vector of headers to include in the request. Each header should be in the formatkey: value.json- The JSON data to send in the request body.timeout- The timeout in seconds for the request.callback- A callback function invoked when the request finishes. It receives the response body, ornilif the request fails or is cancelled.
§Returns
uint64_t- The request id. Returns0when the request cannot be scheduled.
Sourcepub fn post_with_headers_part_async(
url: &str,
headers: &Vec<&str>,
json: &str,
timeout: f32,
part_callback: Box<dyn FnMut(&str) -> bool>,
callback: Box<dyn FnMut(Option<String>)>,
) -> i64
pub fn post_with_headers_part_async( url: &str, headers: &Vec<&str>, json: &str, timeout: f32, part_callback: Box<dyn FnMut(&str) -> bool>, callback: Box<dyn FnMut(Option<String>)>, ) -> i64
Sends a POST request with custom headers and a JSON body, while optionally consuming the response stream in chunks.
§Arguments
url- The URL to send the request to.headers- A vector of headers to include in the request. Each header should be in the formatkey: value.json- The JSON data to send in the request body.timeout- The timeout in seconds for the request.part_callback- A callback function that receives response chunks as they arrive. Returntrueto stop and cancel the request early.callback- A callback function invoked when the request finishes. It receives the full response body, ornilif the request fails or is cancelled.
§Returns
uint64_t- The request id. Returns0when the request cannot be scheduled.
Sourcepub fn get_async(
url: &str,
timeout: f32,
callback: Box<dyn FnMut(Option<String>)>,
) -> i64
pub fn get_async( url: &str, timeout: f32, callback: Box<dyn FnMut(Option<String>)>, ) -> i64
Sends a GET request.
§Arguments
url- The URL to send the request to.timeout- The timeout in seconds for the request.callback- A callback function invoked when the request finishes. It receives the response body, ornilif the request fails or is cancelled.
§Returns
uint64_t- The request id. Returns0when the request cannot be scheduled.
Sourcepub fn download_async(
url: &str,
full_path: &str,
timeout: f32,
progress: Box<dyn FnMut(bool, i64, i64) -> bool>,
) -> i64
pub fn download_async( url: &str, full_path: &str, timeout: f32, progress: Box<dyn FnMut(bool, i64, i64) -> bool>, ) -> i64
Downloads a file asynchronously and saves it to the specified local path.
§Arguments
url- The URL of the file to download.full_path- The full path where the downloaded file should be saved.timeout- The timeout in seconds for the request.progress- A callback function that reports download progress. The function receivesinterrupted(whether the download failed or was cancelled),current(downloaded bytes), andtotal(total bytes when available). Returntrueto cancel the download. If the download fails or is cancelled, the partially written file is removed.
§Returns
uint64_t- The request id. Returns0when the request cannot be scheduled.
Auto Trait Implementations§
impl Freeze for HttpClient
impl RefUnwindSafe for HttpClient
impl Send for HttpClient
impl Sync for HttpClient
impl Unpin for HttpClient
impl UnsafeUnpin for HttpClient
impl UnwindSafe for HttpClient
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