Expand description
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
can be found in our git repository.
use std::process::ExitCode;
use via::{Error, Next, Request, Response, Server};
async fn hello(request: Request, _: Next) -> via::Result {
// Get a reference to the path parameter `name` from the request uri.
let name = request.envelope().param("name").decode().into_result()?;
// Send a plain text response with our greeting message.
Response::build().text(format!("Hello, {}!", name))
}
#[tokio::main]
async fn main() -> Result<ExitCode, Error> {
let mut app = via::app(());
// Define a route that listens on /hello/:name.
app.route("/hello/:name").to(via::get(hello));
Server::new(app).listen(("127.0.0.1", 8080)).await
}Re-exports§
pub use error::Error;pub use request::Payload;pub use request::Request;pub use response::Finalize;pub use response::Response;pub use router::connect;pub use router::delete;pub use router::get;pub use router::head;pub use router::options;pub use router::patch;pub use router::post;pub use router::put;pub use router::trace;
Modules§
Macros§
Structs§
- Continue
- A no-op middleware that simply calls the next middleware in the stack.
- Cookies
- Parse request cookies and serialize response cookies.
- Guard
- Stop processing the request and respond if the provided precondition fails.
- Next
- The next middleware in the logical call stack of a request.
- Server
- Serve an app over HTTP.
- Shared
- Via
- Configure routes and define shared global state.
Traits§
Functions§
- app
- Create a new app with the provided state argument.
Type Aliases§
- BoxFuture
- An alias for the pin
Box<dyn Future>returned by middleware. - Result
- An alias for results that uses the
Errorstruct defined in this crate.