Struct mangadex_api::http_client::HttpClient
source · [−]pub struct HttpClient {
pub client: Client,
pub base_url: Url,
auth_tokens: Option<AuthTokens>,
captcha: Option<String>,
}
Fields
client: Client
base_url: Url
auth_tokens: Option<AuthTokens>
captcha: Option<String>
Implementations
sourceimpl HttpClient
impl HttpClient
sourcepub fn new(client: Client) -> Self
pub fn new(client: Client) -> Self
Create a new HttpClient
with a custom reqwest::Client
.
sourcepub fn builder() -> HttpClientBuilder
pub fn builder() -> HttpClientBuilder
Get a builder struct to customize the HttpClient
fields.
Examples
use url::Url;
use mangadex_api::{MangaDexClient, HttpClient};
let http_client = HttpClient::builder()
.base_url(Url::parse("127.0.0.1:8000")?)
.build()?;
let mangadex_client = MangaDexClient::new_with_http_client(http_client);
sourcepub(crate) async fn send_request_without_deserializing<E>(
&self,
endpoint: &E
) -> Result<Response> where
E: Endpoint,
pub(crate) async fn send_request_without_deserializing<E>(
&self,
endpoint: &E
) -> Result<Response> where
E: Endpoint,
Send the request to the endpoint but don’t deserialize the response.
This is useful to handle things such as response header data for more control over areas such as rate limiting.
sourcepub(crate) async fn send_request<E>(&self, endpoint: &E) -> Result<E::Response> where
E: Endpoint,
<<E as Endpoint>::Response as FromResponse>::Response: DeserializeOwned,
pub(crate) async fn send_request<E>(&self, endpoint: &E) -> Result<E::Response> where
E: Endpoint,
<<E as Endpoint>::Response as FromResponse>::Response: DeserializeOwned,
Send the request to the endpoint and deserialize the response body.
sourcepub fn get_tokens(&self) -> Option<&AuthTokens>
pub fn get_tokens(&self) -> Option<&AuthTokens>
Get the authentication tokens stored in the client.
sourcepub fn set_auth_tokens(&mut self, auth_tokens: &AuthTokens)
pub fn set_auth_tokens(&mut self, auth_tokens: &AuthTokens)
Set new authentication tokens into the client.
sourcepub fn clear_auth_tokens(&mut self)
pub fn clear_auth_tokens(&mut self)
Remove all authentication tokens from the client.
This is effectively the same as logging out, though will not remove the active session from the MangaDex server. Be sure to call the logout endpoint to ensure your session is removed.
sourcepub fn get_captcha(&self) -> Option<&String>
pub fn get_captcha(&self) -> Option<&String>
Get the captcha solution stored in the client.
sourcepub fn set_captcha<T: Into<String>>(&mut self, captcha: T)
pub fn set_captcha<T: Into<String>>(&mut self, captcha: T)
Set a new captcha solution into the client.
The code needed for this can be found in the “X-Captcha-Sitekey” header field,
or the siteKey
parameter in the error context of a 403 response,
captcha_required_exception
error code.
sourcepub fn clear_captcha(&mut self)
pub fn clear_captcha(&mut self)
Remove the captcha solution from the client.
Trait Implementations
sourceimpl Clone for HttpClient
impl Clone for HttpClient
sourcefn clone(&self) -> HttpClient
fn clone(&self) -> HttpClient
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for HttpClient
impl Debug for HttpClient
Auto Trait Implementations
impl !RefUnwindSafe for HttpClient
impl Send for HttpClient
impl Sync for HttpClient
impl Unpin for HttpClient
impl !UnwindSafe for HttpClient
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more