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