pub struct ApiClient {
pub client: Client,
/* private fields */
}Expand description
HTTP client for making API requests with JSON support.
Fields§
§client: ClientImplementations§
Source§impl ApiClient
impl ApiClient
Sourcepub fn new(url: impl Into<String>) -> Self
pub fn new(url: impl Into<String>) -> Self
Creates a new API client with the given base URL.
§Examples
use ej_requests::ApiClient;
let client = ApiClient::new("https://api.example.com");Sourcepub async fn get<T: DeserializeOwned>(&self, endpoint: &str) -> T
pub async fn get<T: DeserializeOwned>(&self, endpoint: &str) -> T
Makes a GET request to the specified endpoint.
Sourcepub async fn get_with_body<T, I, K, V>(&self, endpoint: &str, params: I) -> T
pub async fn get_with_body<T, I, K, V>(&self, endpoint: &str, params: I) -> T
Makes a GET request with query parameters.
Sourcepub async fn post<T: Into<Body>>(
&self,
endpoint: &str,
body: T,
) -> Result<Response, Box<dyn Error>>
pub async fn post<T: Into<Body>>( &self, endpoint: &str, body: T, ) -> Result<Response, Box<dyn Error>>
Makes a POST request with the given body.
Sourcepub async fn post_and_deserialize<T: Into<Body>, U: DeserializeOwned>(
&self,
endpoint: &str,
body: T,
) -> Result<U, Box<dyn Error>>
pub async fn post_and_deserialize<T: Into<Body>, U: DeserializeOwned>( &self, endpoint: &str, body: T, ) -> Result<U, Box<dyn Error>>
Makes a POST request and deserializes the response.
Sourcepub async fn post_no_body<T: DeserializeOwned>(
&self,
endpoint: &str,
) -> Result<T, Box<dyn Error>>
pub async fn post_no_body<T: DeserializeOwned>( &self, endpoint: &str, ) -> Result<T, Box<dyn Error>>
Makes a POST request without a body and deserializes the response.
Auto Trait Implementations§
impl Freeze for ApiClient
impl !RefUnwindSafe for ApiClient
impl Send for ApiClient
impl Sync for ApiClient
impl Unpin for ApiClient
impl !UnwindSafe 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
Mutably borrows from an owned value. Read more