Crates.io | lest |
lib.rs | lest |
version | 0.2.1 |
source | src |
created_at | 2024-08-18 03:58:40.194882 |
updated_at | 2024-08-24 18:13:42.764663 |
description | A modular approach to a web server. Based on actix-web. |
homepage | https://lest.crit.rip |
repository | https://git.crit.rip/lest-rs/lest-lib |
max_upload_size | |
id | 1342311 |
size | 113,330 |
This crate provides a modular abstraction over actix-web
allowing advanced guarding, request/response verification and separate modules. The concepts are designed to be similar to NestJS and ElysiaJS in terms of modularity and request/response verification. It's designed to be easy, and uses my other library libcoerced
to provide advanced verification.
This provides a root route and serves a directory excluding the path routes/**
.
use lest::{models::{guard::Guard, app::App, request::Request, response::{Response, Status}, route::{Route, RouteResponse}, served::Served}, types::method::Method, leaked};
fn route_handler(_req: Request) -> RouteResponse {
Box::pin(async {
let mut response = Response::new(Status::from_u16(302));
response.redirect("/index.html".to_string());
Ok(response)
})
}
let root_route = Route::new(
Method::Get, // Require GET method
route_handler, /// Route handler
None, // NO request verification
None, // NO response verification
Guard::Combine(Box::from([
Guard::Host("localhost"),
Guard::Port(8080),
])) // Enforce host and port
);
let mut app = App::new(("/".to_string(), Some(root_route)));
app.dir(Served {
root: "/".to_string(),
path: "static".to_string(),
index_html: true,
}, Box::from([
"routes/**",
]));
leaked(app)
.serve(
8080,
Box::pin(async {
println!("Server started at http://localhost:8080");
})
).await;
Lest is designed to have everything you need out of the box- no middlewares, no extra dependencies.