1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use crateAppContext;
use ApiRouter;
use Router;
use FromRef;
use Itertools;
/// This method is provided to help build API paths given a parent and child route. This is useful
/// because we recommend building your [`Router`]s and combining them using [`Router::merge`]
/// instead of [`Router::nest`] in order to allow the default-enabled
/// [`tower_http::normalize_path::NormalizePathLayer`] to work for all routes of your app --
/// otherwise, it doesn't work for nested routes.
///
/// # Examples
/// ```rust
/// # use axum::Router;
/// # use roadster::api::http::build_path;
/// # use roadster::app::context::AppContext;
/// # use roadster::service::http::builder::HttpServiceBuilder;
/// #
/// const BASE: &str = "/api";
///
/// async fn http_service(state: &AppContext) -> HttpServiceBuilder<AppContext> {
/// HttpServiceBuilder::new(Some(BASE), state)
/// .router(example_a::routes(BASE))
/// .router(example_b::routes(BASE))
/// }
///
/// mod example_a {
/// # use axum::Router;
/// # use axum::routing::get;
/// # use axum_core::response::IntoResponse;
/// # use roadster::api::http::build_path;
/// # use roadster::app::context::AppContext;
/// #
/// pub fn routes(parent: &str) -> Router<AppContext> {
/// // Use `build_path` to build a path relative to the parent path.
/// Router::new().route(&build_path(parent, "/example_a"), get(example_a))
/// }
///
/// async fn example_a() -> impl IntoResponse {
/// ()
/// }
/// }
///
/// mod example_b {
/// # use axum::Router;
/// # use axum::routing::get;
/// # use axum_core::response::IntoResponse;
/// # use roadster::api::http::build_path;
/// # use roadster::app::context::AppContext;
/// #
/// pub fn routes(parent: &str) -> Router<AppContext> {
/// // Use `build_path` to build a path relative to the parent path.
/// Router::new().route(&build_path(parent, "/example_b"), get(example_a))
/// }
///
/// async fn example_a() -> impl IntoResponse {
/// ()
/// }
/// }
/// ```