Marla is a handler and middleware based web server framework for Rust.
Handlers can be called based on static path maps, regex based paths, and fully custom router functions.
Middleware can be configured to run for all requests by default and overridden for specific routes.
Not yet recommended for production use. Not guaranteed to ever be ready.
Cargo.toml
:
toml
hyper = { version = "0.14", features = ["full"] }
macro_rules_attribute = "0.0"
marla = "0.1.0-alpha.0"
regex = "1.4"
tokio = { version = "1.0", features = ["full"] }
main.rs
:
```rust
use std::collections::HashMap;
use std::net::SocketAddr;
use hyper::{Body, Method, Response}; use macrorulesattribute::macrorulesattribute; use marla::{Request, serve, async_handler}; use marla::config::{MarlaConfig, RegexPath, Route}; use regex::Regex;
async fn main() { let marla_config = MarlaConfig {
regex_path_routes: vec![
RegexPath{
regex: Regex::new("^/hello/([a-zA-Z]{1,30})$").unwrap(),
routes: vec![
(Method::GET, Route { handler: hello, middleware: None }),
].into_iter().collect()
},
],
static_path_routes: HashMap::new(),
router: None,
middleware: vec![],
listen_addr: SocketAddr::from(([127, 0, 0, 1], 3000)),
};
serve(marla_config, ()).await;
}
pub async fn hello( request: Request, body: Option, _bundle: (), ) -> Response { Response::new(Body::from(format!("Hello, {}\n", request.pathparams[0]))) } ```