Skip to main content

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::{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.

Re-exports§

pub use error::Error;
pub use error::ResultExt;
pub use error::rescue;
pub use request::Payload;
pub use request::Request;
pub use response::Finalize;
pub use response::Response;
pub use router::Route;
pub use router::Router;
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;
pub use ws::ws;

Modules§

error
Raise and recover from service errors with a capability-bounded policy.
guard
Predicate-based request filters that define the middleware stack shape.
request
Interact with incoming requests to your service.
response
Build, finalize, and decorate responses from middleware.
router
A declarative routing DSL that makes trust boundaries obvious.
ws
Support bidirectional communication over HTTP with WebSockets.

Macros§

deny
Return an error from a format string or error source.
err
Construct an error from a format string or error source.
resource
Generate traditional REST scopes for a resource module.

Structs§

Before
A middleware adapter that decorates a request before delegation.
Continue
A no-op middleware that simply calls the next middleware in the stack.
Cookies
Parse and manage the specified request and response cookies.
Next
A linear, single-use execution cursor over middleware.
Server
Serve an app over HTTP.
Shared
A thread-safe, reference-counting pointer to the application.

Traits§

Middleware
An asynchronous step in the request processing pipeline.

Functions§

before
Creates middleware that decorates a request before invoking another middleware.
cookies
Parse and manage the specified request and response cookies.
middleware
Define middleware as a function that may capture its environment.

Type Aliases§

BoxFuture
An alias for the pin Box<dyn Future> returned by middleware.
Result
An alias for results that uses the Error struct defined in this crate.