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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
//! # RustyX
//!
//! A fast, minimalist web framework for Rust inspired by ExpressJS.
//!
//! RustyX provides an ExpressJS-like interface for building web APIs in Rust,
//! with built-in ORM support for MongoDB, MySQL, SQLite, and PostgreSQL.
//!
//! ## Features
//!
//! - 🎯 **ExpressJS-like API** - Familiar interface for JavaScript developers
//! - ⚡ **Blazingly Fast** - Built on Hyper and Tokio for maximum performance
//! - 🔌 **Middleware Support** - Logger, CORS, Rate Limiting, Helmet, Timeout
//! - 📤 **File Upload** - Multer-like file upload with validation
//! - 🗄️ **Multi-Database ORM** - MongoDB, MySQL, PostgreSQL, SQLite support
//! - 🌐 **WebSocket Support** - Real-time bidirectional communication
//! - 📁 **Static Files** - Serve static assets with MIME type detection
//! - 🔒 **Type-Safe** - Leverage Rust's type system for safer code
//!
//! ## Quick Start
//!
//! ```rust,no_run
//! use rustyx::prelude::*;
//!
//! #[tokio::main]
//! async fn main() -> Result<()> {
//! let app = RustyX::new();
//!
//! app.get("/", |_req, res| async move {
//! res.json(json!({ "message": "Hello, World!" }))
//! });
//!
//! app.listen(3000).await
//! }
//! ```
//!
//! ## Routing
//!
//! RustyX supports all common HTTP methods with ExpressJS-style routing:
//!
//! ```rust,no_run
//! use rustyx::prelude::*;
//!
//! #[tokio::main]
//! async fn main() -> Result<()> {
//! let app = RustyX::new();
//!
//! // GET request
//! app.get("/users", |_req, res| async move {
//! res.json(json!({ "users": [] }))
//! });
//!
//! // POST request
//! app.post("/users", |req, res| async move {
//! // Parse JSON body
//! let data: serde_json::Value = req.json().unwrap_or_default();
//! res.status(201).json(data)
//! });
//!
//! // URL parameters
//! app.get("/users/:id", |req, res| async move {
//! let id = req.param("id").unwrap();
//! res.json(json!({ "user_id": id }))
//! });
//!
//! app.listen(3000).await
//! }
//! ```
//!
//! ## Middleware
//!
//! Add middleware for cross-cutting concerns:
//!
//! ```rust,no_run
//! use rustyx::prelude::*;
//!
//! #[tokio::main]
//! async fn main() -> Result<()> {
//! let app = RustyX::new();
//!
//! // Built-in middleware
//! app.use_middleware(logger()); // Request logging
//! app.use_middleware(cors("*")); // CORS headers
//! app.use_middleware(helmet()); // Security headers
//! app.use_middleware(timeout(30000)); // 30s timeout
//!
//! // Rate limiting
//! let rate_config = RateLimiterConfig::new(100, 60);
//! app.use_middleware(rate_limiter(rate_config));
//!
//! app.get("/", |_req, res| async move {
//! res.json(json!({ "status": "ok" }))
//! });
//!
//! app.listen(3000).await
//! }
//! ```
//!
//! ## Request Object
//!
//! The [`Request`] object provides access to request data:
//!
//! - `req.method()` - HTTP method
//! - `req.path()` - Request path
//! - `req.param("name")` - URL parameters
//! - `req.query_param("key")` - Query parameters
//! - `req.json::<T>()` - Parse JSON body
//! - `req.header("name")` - Get header value
//! - `req.bearer_token()` - Extract Bearer token
//! - `req.ip()` - Client IP address
//!
//! ## Response Object
//!
//! The [`Response`] object provides methods for sending responses:
//!
//! - `res.json(data)` - Send JSON response
//! - `res.send("text")` - Send text response
//! - `res.html("<html>")` - Send HTML response
//! - `res.status(201)` - Set status code
//! - `res.redirect("/path")` - Send redirect
//! - `res.header("name", "value")` - Set header
//!
//! ## File Upload
//!
//! Handle file uploads similar to Express Multer:
//!
//! ```rust,no_run
//! use rustyx::prelude::*;
//!
//! #[tokio::main]
//! async fn main() -> Result<()> {
//! let app = RustyX::new();
//!
//! // Create uploader configuration
//! let uploader = Uploader::new(
//! UploadConfig::new()
//! .destination("./uploads")
//! .max_file_size_mb(5)
//! .allowed_extensions(vec!["png", "jpg", "jpeg", "pdf"])
//! );
//!
//! app.post("/upload", move |req, res| {
//! let uploader = uploader.clone();
//! async move {
//! // Parse multipart form data
//! let content_type = req.content_type().unwrap_or_default();
//! let boundary = parse_boundary(&content_type).unwrap();
//! let fields = parse_multipart(req.body(), &boundary).unwrap();
//!
//! for field in fields {
//! if let Some(filename) = field.filename {
//! let result = uploader.upload_single(
//! &field.name,
//! field.data,
//! &filename,
//! &field.content_type.unwrap_or_default()
//! ).await;
//!
//! match result {
//! Ok(file) => return res.json(json!({
//! "filename": file.filename,
//! "size": file.size
//! })),
//! Err(e) => return res.bad_request(&e.to_string())
//! }
//! }
//! }
//! res.bad_request("No file provided")
//! }
//! });
//!
//! app.listen(3000).await
//! }
//! ```
//!
//! ### Upload Configuration Options
//!
//! | Method | Description |
//! |--------|-------------|
//! | `.destination("./uploads")` | Set upload directory |
//! | `.max_file_size_mb(10)` | Max file size in MB |
//! | `.max_files(5)` | Max files per request |
//! | `.images_only()` | Only allow image files |
//! | `.documents_only()` | Only allow document files |
//! | `.allowed_extensions(vec!["png", "pdf"])` | Custom allowed extensions |
//! | `.allowed_types(vec!["image/png"])` | Custom allowed MIME types |
//! | `.keep_original_name()` | Keep original filename |
//! | `.use_uuid()` | Use UUID for filename |
//!
//! ### Supported File Types
//!
//! **Images:** PNG, JPG, JPEG, GIF, WebP, SVG, ICO, BMP, TIFF
//!
//! **Documents:** PDF, DOC, DOCX, XLS, XLSX, PPT, PPTX, TXT, CSV
//!
//! **Media:** MP3, WAV, OGG, MP4, WebM, AVI, MOV
//!
//! **Archives:** ZIP, RAR, 7Z, TAR, GZ
//!
//! ## Feature Flags
//!
//! | Feature | Description |
//! |---------|-------------|
//! | `default` | SQLite support enabled |
//! | `mysql` | MySQL database support |
//! | `postgres` | PostgreSQL database support |
//! | `sqlite` | SQLite database support |
//! | `mongodb` | MongoDB database support |
//! | `full` | All database drivers enabled |
//!
//! ## Modules
//!
//! - [`app`] - Main application struct
//! - [`router`] - Routing functionality
//! - [`request`] - Request handling
//! - [`response`] - Response building
//! - [`middleware`] - Middleware functions
//! - [`upload`] - File upload handling
//! - [`db`] - Database integration
//! - [`websocket`] - WebSocket support
//! - [`static_files`] - Static file serving
// TODO: Add docs for all public items before 1.0
// Re-exports for convenience
pub use RustyX;
pub use ;
pub use ;
pub use Request;
pub use Response;
pub use Router;
pub use ;
pub use ;
pub use ;
/// Prelude module for convenient imports.
///
/// Import everything you need with a single line:
///
/// ```rust
/// use rustyx::prelude::*;
/// ```
///
/// This includes:
/// - [`RustyX`] - Main application struct
/// - [`Request`] and [`Response`] - HTTP handling
/// - [`Router`] - Route grouping
/// - All middleware functions
/// - Serde traits and macros
/// - Tracing macros
/// Version of the RustyX library.
///
/// # Example
///
/// ```rust
/// println!("RustyX version: {}", rustyx::VERSION);
/// ```
pub const VERSION: &str = env!;
/// Name of the library.
pub const NAME: &str = "RustyX";
/// GitHub repository URL.
pub const REPOSITORY: &str = "https://github.com/Mohammad007/rustyx";
/// Documentation URL.
pub const DOCS_URL: &str = "https://docs.rs/rustyx";