1 unstable release
0.0.0 | Nov 29, 2023 |
---|
#277 in #middleware
19KB
364 lines
⚡️ Quick Start
use cors middleware
use hypers_middleware's cors feature
use hypers::prelude::*;
use hypers_middleware::Cors;
#[get("return_str")]
async fn return_str() -> &'static str {
"return_str"
}
fn main() -> Result<()> {
let mut root = Router::new("/");
let cors = Cors::new()
.allow_origin("*")
.allow_methods(vec!["GET", "POST"])
.allow_headers(vec![
"CONTENT-TYPE",
"Access-Control-Request-Method",
"Access-Control-Allow-Origin",
"Access-Control-Allow-Headers",
"Access-Control-Max-Age",
]);
root.hook(cors, vec!["/"], None);
root.handler(return_str);
println!("root = {:#?}",root);
hypers::run(root, "127.0.0.1:7878")
}
use compression middleware
use hypers's static_file feature
use hypers_middleware's compression feature
use hypers::prelude::*;
use hypers_middleware::Compression;
fn main() -> Result<()> {
let mut root = Router::new("/");
root.hook(Compression::Deflate,vec!["/"],None);
root.get("readme",StaticFile::new("hypers_middleware/README.md"));
println!("root = {:#?}",root);
hypers::run(root,"127.0.0.1:7878")
}
Dependencies
~13–27MB
~515K SLoC