pub struct ApiClient {
pub http: Client,
pub state: ApiClientState,
pub host: String,
}Expand description
The API client is used to manage authentication flow and send requests on behalf of a user.
This client assumes you already have the required information for the given user. If you don’t, try using the JS SDK to extract this information.
Fields§
§http: ClientThe HTTP client associated with this client.
state: ApiClientStateThe general state of the client. Will be updated whenever you refresh the user’s token.
host: StringThe origin of the Tetratto server. When creating with ApiClient::new,
you can provide None to use https://tetratto.com.
Implementations§
Source§impl ApiClient
impl ApiClient
Sourcepub async fn refresh_token(&mut self) -> Result<String>
pub async fn refresh_token(&mut self) -> Result<String>
Refresh the client’s user_token.
Sourcepub async fn request<T, B>(
&self,
route: String,
method: Method,
body: Option<&B>,
) -> Result<ApiReturn<T>>
pub async fn request<T, B>( &self, route: String, method: Method, body: Option<&B>, ) -> Result<ApiReturn<T>>
Send a simple JSON request to the given endpoint.
Sourcepub async fn request_attachments<T, B>(
&self,
route: String,
attachments: Vec<Vec<u8>>,
body: &B,
) -> Result<ApiReturn<T>>
pub async fn request_attachments<T, B>( &self, route: String, attachments: Vec<Vec<u8>>, body: &B, ) -> Result<ApiReturn<T>>
Send a JSON request with attachments to the given endpoint.
This type of request is only required for routes which use JsonMultipart,
such as POST /api/v1/posts (create_post).
Method is locked to POST for this type of request.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for ApiClient
impl !UnwindSafe for ApiClient
impl Freeze for ApiClient
impl Send for ApiClient
impl Sync for ApiClient
impl Unpin for ApiClient
impl UnsafeUnpin for ApiClient
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more