restless_core/
get.rs

1use super::*;
2
3/// GET [`Request`] method.
4///
5/// The GET method requests a representation of the specified resource. Requests using GET should
6/// only retrieve data.
7pub trait GetRequest: Sized {
8    /// Response type and encoding.
9    type Response: Decodable;
10
11    /// Query type.
12    type Query: ToQuery;
13
14    /// URI path.
15    fn path(&self) -> Cow<'_, str>;
16
17    /// Query parameters.
18    fn query(&self) -> Self::Query;
19
20    /// Turn this into a [`Request`].
21    fn request(self) -> Get<Self> {
22        self.into()
23    }
24}
25
26impl<T: GetRequest> GetRequest for &T {
27    type Response = T::Response;
28    type Query = T::Query;
29
30    fn path(&self) -> Cow<'_, str> {
31        <T as GetRequest>::path(self)
32    }
33
34    fn query(&self) -> Self::Query {
35        <T as GetRequest>::query(self)
36    }
37}
38
39impl<T: GetRequest> Request for Get<T> {
40    type Request = ();
41    type Response = T::Response;
42    type Query = T::Query;
43
44    fn path(&self) -> Cow<'_, str> {
45        self.inner.path()
46    }
47
48    fn body(&self) -> Self::Request {}
49
50    fn query(&self) -> Self::Query {
51        self.inner.query()
52    }
53
54    fn method(&self) -> Method {
55        Method::Get
56    }
57}