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::{App, BoxError, Next, Request, Response};
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() -> Result<ExitCode, BoxError> {
let mut app = App::new(());
// Define a route that listens on /hello/:name.
app.at("/hello/:name").respond(via::get(hello));
via::serve(app).listen(("127.0.0.1", 8080)).await
}Re-exports§
Modules§
Macros§
- raise
- Wrap an existing error or construct a new one by providing a status code.
Structs§
- Allow
- Middleware for routing based on the HTTP method of the request.
- App
- Next
- Route
- Server
- Serve an app over HTTP.
- Timeout
Traits§
- Middleware
- Payload
- Interact with data received from a client.
- Pipe
- Define how a type becomes a
Response.
Functions§
- connect
- Allow
CONNECTrequests to call the provided middleware. - delete
- Allow
DELETErequests to call the provided middleware. - get
- Allow
GETrequests to call the provided middleware. - head
- Allow
HEADrequests to call the provided middleware. - options
- Allow
OPTIONSrequests to call the provided middleware. - patch
- Allow
PATCHrequests to call the provided middleware. - post
- Allow
POSTrequests to call the provided middleware. - put
- Allow
PUTrequests to call the provided middleware. - rescue
- Recover from errors that occur in downstream middleware.
- serve
- Creates a new server for the provided app.
- timeout
- Create a new
Timeoutmiddleware with the specified duration. - trace
- Allow
TRACErequests to call the provided middleware. - ws
- Upgrade the connection to a web socket.