stellation_backend/request.rs
1use http::HeaderMap;
2use serde::{Deserialize, Serialize};
3
4use crate::ServerAppResult;
5
6/// A trait that describes a request received by the backend.
7pub trait Request {
8 /// A request context that can be used to provide other information.
9 type Context;
10
11 /// Returns the path of current request.
12 fn path(&self) -> &str;
13
14 /// Returns queries as a raw string.
15 fn raw_queries(&self) -> &str;
16
17 /// Returns the headers of current request.
18 fn headers(&self) -> &HeaderMap;
19
20 /// Returns queries of current request.
21 fn queries<Q>(&self) -> ServerAppResult<Q>
22 where
23 Q: Serialize + for<'de> Deserialize<'de>,
24 {
25 Ok(serde_urlencoded::from_str(self.raw_queries())?)
26 }
27
28 /// Returns the current request context.
29 fn context(&self) -> &Self::Context;
30}
31
32/// A trait that describes a request for server-side rendering.
33pub trait RenderRequest: Request {
34 /// Returns the template of the html file.
35 fn template(&self) -> &str;
36
37 /// Returns true if this request should be rendered at the client side.
38 fn is_client_only(&self) -> bool;
39}