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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//! # Router Module
//!
//! This module provides the [`Router`] type for grouping related routes under a
//! common base path and mounting them to an [`App`]. It mirrors Express-style
//! routers, enabling clean organization, versioning, and composition of APIs.
//!
//! ## Key Features
//!
//! - **Grouping**: Collect handlers under a single base path
//! - **Composition**: Build routers in isolation and mount onto an `App`
//! - **Versioning**: Create versioned APIs like `/v1`, `/v2`
//! - **Familiar ergonomics**: Same `get/post/put/delete/patch/head/options` API as `App`
//!
//! ## Basic Usage
//!
//! ```rust
//! use ripress::{router::Router, app::App};
//! use ripress::types::RouterFns;
//! use ripress::{req::HttpRequest, res::HttpResponse};
//!
//! async fn hello_handler(_req: HttpRequest, res: HttpResponse) -> HttpResponse {
//! res.ok().text("Hello from router")
//! }
//!
//! let mut router = Router::new("/api");
//! router.get("/hello", hello_handler);
//!
//! let mut app = App::new();
//! app.router(router);
//! ```
//!
//! ## Versioning Example
//!
//! ```rust
//! use ripress::{router::Router, app::App};
//! use ripress::types::RouterFns;
//! use ripress::{req::HttpRequest, res::HttpResponse};
//!
//! async fn status(_req: HttpRequest, res: HttpResponse) -> HttpResponse {
//! res.ok().json(serde_json::json!({"status": "ok"}))
//! }
//!
//! let mut v1 = Router::new("/v1");
//! v1.get("/status", status);
//!
//! let mut app = App::new();
//! v1.register(&mut app);
//! ```
use crate::;
use HashMap;
/// A modular router for grouping and mounting routes under a common base path.
///
/// The `Router` struct allows you to organize related routes together and mount them
/// onto an application at a specified base path. This is useful for building APIs
/// with versioning, grouping endpoints, or composing applications from multiple routers.
///
/// # Example
///
/// ```
/// use ripress::{router::Router, app::App};
/// use ripress::{req::HttpRequest, res::HttpResponse};
/// use ripress::types::RouterFns;
///
/// async fn handler(req: HttpRequest, res: HttpResponse) -> HttpResponse {
/// res.ok().text("Hello, World!")
/// }
///
/// let mut router = Router::new("/api");
/// router.get("/hello", handler);
/// let mut app = App::new();
/// app.router(router);
/// ```