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
// #![deny(missing_docs)]
//! An async multi-threaded web framework for people who appreciate simplicity.
//!
//! Documentation is sparse at the moment, but the code is well-commented for
//! the most part.
//!
//! If you're interested in contributing, helping with documentation is a great
//! starting point.
//!
//! ## Hello World Example
//!
//! Below is a basic example to demonstrate how to use Via to create a simple
//! web server that responds to requests at `/hello/:name` with a personalized
//! greeting.
//! [Additional examples](https://github.com/zacharygolba/via/tree/main/examples)
//! can be found in our git repository.
//!
//! ```no_run
//! use std::process::ExitCode;
//! use via::{Next, Request, Response, ResultExt, Router, Server};
//!
//! async fn hello(request: Request, _: Next) -> via::Result {
//! // Get a reference to the path parameter `name` from the request uri.
//! let name = request.param("name").percent_decode().into_result()?;
//!
//! // Send a plain text response with our greeting message.
//! Response::build().text(format!("Hello, {}!", name))
//! }
//!
//! #[tokio::main]
//! async fn main() -> via::Result<ExitCode> {
//! // Define the routes that our application responds to.
//! let router = Router::new(|home| {
//! // Start defining descendants of "/".
//! let mut path = home.prefix();
//!
//! // Define a route that listens on /hello/:name.
//! path.route("/hello/:name", via::get(hello));
//! });
//!
//! // Serve the application at http://localhost:8080/.
//! Server::new(router, ()).listen(("127.0.0.1", 8080)).await
//! }
//! ```
//!
//! # Dedication
//!
//! For Chester and Kristina. Make them smile. Build something that you are
//! proud of.
//!
",
"",
stringify!($level),
stringify!($name),
format_args!($fmt $(, $($arg),*)?),
indent = $indent * 2,
);
};
}
pub mod error;
pub mod guard;
pub mod request;
pub mod response;
pub mod router;
#[cfg(any(feature = "tokio-tungstenite", feature = "tokio-websockets"))]
pub mod ws;
mod app;
mod before;
mod cookies;
mod middleware;
mod next;
mod server;
mod util;
pub use via_macros::resource;
pub use app::Shared;
pub use before::{Before, before};
pub use cookies::{Cookies, cookies};
pub use error::{Error, ResultExt, rescue};
pub use middleware::{BoxFuture, Middleware, Result, middleware};
pub use next::{Continue, Next};
pub use request::{Payload, Request};
pub use response::{Finalize, Response};
pub use router::{Route, Router, delete, get, head, options, patch, post, put, trace};
pub use server::Server;
#[cfg(any(feature = "tokio-tungstenite", feature = "tokio-websockets"))]
pub use ws::ws;