saphir 2.6.6

Fully async-await http server framework
Documentation

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 {}

#[controller]
impl TestController {
#[get("/{var}/print")]
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"))
}

#[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)
.controller(TestController {})
})
.build();

// Start server with
// server.run().await
#    Ok(())
}

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