Crates.io | saphir-cli |
lib.rs | saphir-cli |
version | 0.5.1 |
source | src |
created_at | 2020-06-17 18:49:53.771066 |
updated_at | 2023-01-09 13:19:43.402693 |
description | CLI utility for the Saphir web framework |
homepage | https://github.com/richerarc/saphir |
repository | https://github.com/richerarc/saphir |
max_upload_size | |
id | 255001 |
size | 133,839 |
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
}