| Crates.io | nous |
| lib.rs | nous |
| version | 0.1.10-beta |
| created_at | 2025-03-19 16:14:23.317493+00 |
| updated_at | 2025-04-06 11:48:14.306953+00 |
| description | lightweight and efficient web framework in Rust designed for handling HTTP requests with built-in gatekeeping middleware. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1598235 |
| size | 50,143 |
Gates is a lightweight and efficient web framework in Rust designed for handling HTTP requests with built-in gatekeeping middleware.
Add gates-rs as a dependency in your Cargo.toml:
[dependencies]
gates-rs = "0.1.0-beta"
// POST request handler
#[gates(post = "/billionaire", gatekeeper = billionairehari)]
fn basicb(b: &GatesRequest) -> GateKeeperResponse {
println!("{}", b.body);
GateResponse::response(GatesResponse::new().status(200).message(""))
}
Middleware functions can intercept requests before they reach handlers.
fn billionairehari(billionaire: &GatesRequest) -> GateKeeperResponse {
let path = billionaire.path;
GateKeeper::next()
GateKeeper::redirect(307, "/billionaires")
GateKeeper::response(
GatesResponse::new()
.content_type("")
.status(404)
.message("billionairegreatharigreat"),
)
}
// GET
#[gates(get = "/billionaire", gatekeeper = billionairehari)]
fn basicg(b: &GatesRequest) -> GateKeeperResponse {
println!("{}", b.body);
GateResponse::response(GatesResponse::new().status(200).message(""))
}
// DELETE
#[gates(delete = "/billionaire", gatekeeper = billionairehari)]
fn basicd(b: &GatesRequest) -> GateKeeperResponse {
println!("{}", b.body);
GateResponse::response(GatesResponse::new().status(200).message(""))
}
// PUT
#[gates(put = "/billionaire", gatekeeper = billionairehari)]
fn basicp(b: &GatesRequest) -> GateKeeperResponse {
println!("{}", b.body);
GateResponse::response(GatesResponse::new().status(200).message(""))
}
#[gates(sse = "/billionaire", gatekeeper = billionairehari)]
fn basics(b: &GatesRequest) -> GateKeeperResponse {
println!("{}", b.body);
GateResponse::response(GatesResponse::new().status(200).message(""))
}
Compile and run the project with:
cargo run
This project is licensed under the MIT License.