Crates.io | marla |
lib.rs | marla |
version | 0.1.0-alpha.1 |
source | src |
created_at | 2021-02-10 05:07:13.434512 |
updated_at | 2021-02-20 03:18:34.120924 |
description | Async Web Server Framework |
homepage | |
repository | https://github.com/MarkSort/marla |
max_upload_size | |
id | 353079 |
size | 21,668 |
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.
You can run this example in examples/hello and browse to http://localhost:3000/hello/world , or use curl
:
curl -sS http://localhost:3000/hello/world -D-
Cargo.toml
:
[dependencies]
hyper = { version = "0.14", features = ["full"] }
macro_rules_attribute = "0.0"
marla = "0.1.0-alpha.1"
regex = "1.4"
tokio = { version = "1.0", features = ["full"] }
main.rs
:
use std::net::SocketAddr;
use hyper::{Body, Method, Response};
use macro_rules_attribute::macro_rules_attribute;
use marla::{Request, serve, async_handler};
use marla::config::{MarlaConfig, RegexPath, Route};
use regex::Regex;
#[tokio::main]
async fn main() {
let marla_config = MarlaConfig {
routers: vec![Box::new(vec![
RegexPath{ regex: Regex::new("^/hello/([a-zA-Z]{1,30})$").unwrap(), routes: vec![
(Method::GET, Route { handler: hello, middleware: None }),
].into_iter().collect()},
])],
middleware: vec![],
listen_addr: SocketAddr::from(([127, 0, 0, 1], 3000)),
};
serve(marla_config, ()).await;
}
#[macro_rules_attribute(async_handler!)]
pub async fn hello(
request: Request,
_body: Option<Body>,
_bundle: (),
) -> Response<Body> {
Response::new(Body::from(format!("Hello, {}\n", request.path_params[0])))
}