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.