Crate saphir[][src]

Expand description

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 Overview

Saphir provide multiple functionality through features. To try it out without fuss, we suggest that use all the features:

saphir = { version = "2.0.0", features = ["full"] }

Then bootstrapping the server is as easy as:

use saphir::prelude::*;

struct TestController {}

impl TestController {
    async fn print_test(&self, var: String) -> (u16, String) {
        (200, var)

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

async fn main() -> Result<(), SaphirError> {

    let server = Server::builder()
        .configure_listener(|l| {
        .configure_router(|r| {
            r.route("/{variable}/print", Method::GET, test_handler)
                .controller(TestController {})

    // Start server with

Saphir’s Features

Even though we strongly recommend that you use at least the macro feature, Saphir will work without any of the following feature, Saphir’s features don’t rely on each other to work.

  • macro : Enable the #[controller] macro attribute for code generation, Recommended and active by default
  • https : Provide everything to allow Saphir server to listen an accept HTTPS traffic
  • json : Add the Json wrapper type to simplify working with json data
  • form : Add the Form wrapper type to simplify working with urlencoded data

More feature will be added in the future


pub use http;


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

Error definitions


A guard is called before the request is processed by the router and can modify the request data or stops request processing by returning a response immediately.

Definition of types which can handle an http request

Context enveloping every request <-> response


Saphir macro for code generation Saphir provides a proc_macro attribute and multiple function attributes.

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.


The async Multipart Form-Data representation

Contains everything you need to bootstrap your http server


The Http Request type

Definition of type which can map to a response

The Http Response type

Router is responsible for redirecting requests to handlers.

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