Crate via

Crate via 

Source
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§

pub use error::Error;
pub use request::Request;
pub use response::Response;

Modules§

cookies
error
Error handling.
request
response
ws

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 CONNECT requests to call the provided middleware.
delete
Allow DELETE requests to call the provided middleware.
get
Allow GET requests to call the provided middleware.
head
Allow HEAD requests to call the provided middleware.
options
Allow OPTIONS requests to call the provided middleware.
patch
Allow PATCH requests to call the provided middleware.
post
Allow POST requests to call the provided middleware.
put
Allow PUT requests 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 Timeout middleware with the specified duration.
trace
Allow TRACE requests to call the provided middleware.
ws
Upgrade the connection to a web socket.

Type Aliases§

BoxError
A type alias for a boxed dyn Error + Send + Sync.
Result
The output of the Future returned from middleware.