Skip to main content

barter_integration/protocol/http/rest/
mod.rs

1use std::time::Duration;
2
3/// Configurable [`client::RestClient`] capable of executing signed [`RestRequest`]s and parsing
4/// responses.
5pub mod client;
6
7/// Default Http [`reqwest::Request`] timeout Duration.
8const DEFAULT_HTTP_REQUEST_TIMEOUT: Duration = Duration::from_secs(5);
9
10/// Http REST request that can be executed by a [`RestClient`](client::RestClient).
11pub trait RestRequest {
12    /// Expected response type if this request was successful.
13    type Response: serde::de::DeserializeOwned;
14
15    /// Serialisable query parameters type - use unit struct () if not required for this request.
16    type QueryParams: serde::Serialize;
17
18    /// Serialisable Body type - use unit struct () if not required for this request.
19    type Body: serde::Serialize;
20
21    /// Additional [`Url`](url::Url) path to the resource.
22    fn path(&self) -> std::borrow::Cow<'static, str>;
23
24    /// Http [`reqwest::Method`] of this request.
25    fn method() -> reqwest::Method;
26
27    /// Optional query parameters for this request.
28    fn query_params(&self) -> Option<&Self::QueryParams> {
29        None
30    }
31
32    /// Optional Body for this request.
33    fn body(&self) -> Option<&Self::Body> {
34        None
35    }
36
37    /// Http request timeout [`Duration`].
38    fn timeout() -> Duration {
39        DEFAULT_HTTP_REQUEST_TIMEOUT
40    }
41}