Crates.io | saphir_macro |
lib.rs | saphir_macro |
version | 2.2.0 |
source | src |
created_at | 2020-02-28 02:51:12.885945 |
updated_at | 2023-01-09 13:19:09.656634 |
description | Macro generation for http server framework |
homepage | https://github.com/richerarc/saphir |
repository | https://github.com/richerarc/saphir |
max_upload_size | |
id | 213409 |
size | 81,371 |
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
}