pub struct RestClient {
pub client: ClientWithMiddleware,
pub url: Url,
}Expand description
A reqwest client (with middleware) and a base url, which can make “REST” (http-json) requests and parse responses according to serde-schema.
All errors retain context about the url, method, and route requested, and at what point in the process the failure occurred.
The RestClient is agnostic about how you initialize ClientWithMiddleware and Url.
If you like you may use CommonConfig to setup timeouts and retries on a reqwest::ClientBuilder.
Fields§
§client: ClientWithMiddlewareThe client to use to make requests
url: UrlThe base url of the API, to which routes are joined
Implementations§
Source§impl RestClient
impl RestClient
Sourcepub async fn request<S: Serialize, T: DeserializeOwned>(
&self,
method: Method,
route: impl AsRef<str> + Debug,
data: &S,
) -> Result<T, Error>
pub async fn request<S: Serialize, T: DeserializeOwned>( &self, method: Method, route: impl AsRef<str> + Debug, data: &S, ) -> Result<T, Error>
Makes a request for given method, route, and data. If it is a GET request, the data is url encoded as query params, otherwise it becomes json in the request body.
Auto Trait Implementations§
impl !RefUnwindSafe for RestClient
impl !UnwindSafe for RestClient
impl Freeze for RestClient
impl Send for RestClient
impl Sync for RestClient
impl Unpin for RestClient
impl UnsafeUnpin for RestClient
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