Crates.io | saphir |
lib.rs | saphir |
version | 3.1.1 |
source | src |
created_at | 2018-06-01 05:00:09.431108 |
updated_at | 2023-04-18 12:22:08.109344 |
description | Fully async-await http server framework |
homepage | https://github.com/richerarc/saphir |
repository | https://github.com/richerarc/saphir |
max_upload_size | |
id | 68019 |
size | 323,113 |
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.
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();
server.run().await
}