pub struct HttpClient { /* private fields */ }Expand description
HTTP client for making API requests
Provides GET, POST, POST form, POST JSON, and multipart file upload methods with automatic retry and error handling
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub fn new(config: HttpClientConfig) -> NetDiskResult<Self>
pub fn new(config: HttpClientConfig) -> NetDiskResult<Self>
Create a new HTTP client with the given configuration
§Examples
use baidu_netdisk_sdk::http::{HttpClient, HttpClientConfig};
let config = HttpClientConfig::default();
let client = HttpClient::new(config)?;Sourcepub fn try_default() -> NetDiskResult<Self>
pub fn try_default() -> NetDiskResult<Self>
Create a default HTTP client
§Examples
use baidu_netdisk_sdk::http::HttpClient;
let client = HttpClient::try_default()?;Sourcepub async fn get<T: DeserializeOwned>(
&self,
url: &str,
params: Option<&[(&str, &str)]>,
) -> NetDiskResult<T>
pub async fn get<T: DeserializeOwned>( &self, url: &str, params: Option<&[(&str, &str)]>, ) -> NetDiskResult<T>
Send GET request and parse JSON response
§Examples
use baidu_netdisk_sdk::http::HttpClient;
use serde::Deserialize;
#[derive(Deserialize)]
struct Response {
// fields
}
let client = HttpClient::try_default()?;
let response: Response = client.get("https://example.com/api", None).await?;Sourcepub async fn get_with_headers<T: DeserializeOwned>(
&self,
url: &str,
params: Option<&[(&str, &str)]>,
headers: Option<&[(&str, &str)]>,
) -> NetDiskResult<T>
pub async fn get_with_headers<T: DeserializeOwned>( &self, url: &str, params: Option<&[(&str, &str)]>, headers: Option<&[(&str, &str)]>, ) -> NetDiskResult<T>
Send GET request with custom headers and parse JSON response
Sourcepub async fn post_form<T: DeserializeOwned>(
&self,
url: &str,
form: Option<&[(&str, &str)]>,
params: Option<&[(&str, &str)]>,
) -> NetDiskResult<T>
pub async fn post_form<T: DeserializeOwned>( &self, url: &str, form: Option<&[(&str, &str)]>, params: Option<&[(&str, &str)]>, ) -> NetDiskResult<T>
Send POST form request and parse JSON response
Sourcepub async fn post<T: DeserializeOwned>(
&self,
url: &str,
params: Option<&[(&str, &str)]>,
) -> NetDiskResult<T>
pub async fn post<T: DeserializeOwned>( &self, url: &str, params: Option<&[(&str, &str)]>, ) -> NetDiskResult<T>
Send POST request with query parameters and parse JSON response
Sourcepub async fn post_json<T: DeserializeOwned, U: Serialize + ?Sized>(
&self,
url: &str,
body: &U,
) -> NetDiskResult<T>
pub async fn post_json<T: DeserializeOwned, U: Serialize + ?Sized>( &self, url: &str, body: &U, ) -> NetDiskResult<T>
Send POST JSON request and parse JSON response
Sourcepub async fn post_multipart<T: DeserializeOwned>(
&self,
url: &str,
field_name: String,
file_name: String,
data: Vec<u8>,
) -> NetDiskResult<T>
pub async fn post_multipart<T: DeserializeOwned>( &self, url: &str, field_name: String, file_name: String, data: Vec<u8>, ) -> NetDiskResult<T>
Send multipart file POST request and parse JSON response
Trait Implementations§
Source§impl Clone for HttpClient
impl Clone for HttpClient
Source§fn clone(&self) -> HttpClient
fn clone(&self) -> HttpClient
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto 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