[][src]Crate saphir

Saphir is a fully async-await http server framework for rust

The goal is to give low-level control to your web stack (as hyper does) without the time consuming task of doing everything from scratch.

Just use the prelude module, and you're ready to go!

Quick server setup

This example is not tested
use saphir::prelude::*;


async fn test_handler(mut req: Request<Body>) -> (u16, Option<String>) {
    (200, req.captures_mut().remove("variable"))
}

#[tokio::main]
async fn main() -> Result<(), SaphirError> {
    env_logger::init();

    let server = Server::builder()
        .configure_listener(|l| {
            l.interface("127.0.0.1:3000")
        })
        .configure_router(|r| {
            r.route("/{variable}/print", Method::GET, test_handler)
        })
        .build().await?;

    server.run().await
}

Re-exports

pub use cookie;
pub use http;
pub use hyper;

Modules

controller

Controllers are responsible for handling requests and returning responses to the client.

error

Error definitions

handler

Definition of types which can handle an http request

http_context

Context enveloping every request <-> response

middleware

A middleware is an object being called before the request is processed by the router, allowing to continue or stop the processing of a given request by calling / omitting next.

prelude

Contains everything you need to bootstrap your http server

request

The Http Request type

responder

Definition of type which can map to a response

response

The Http Response type

router
server

Server implementation and default runtime Server is the centerpiece on saphir, it contains everything to handle request and dispatch it the proper router

utils