hypers_middleware

Crates.iohypers_middleware
lib.rshypers_middleware
version0.0.0
sourcesrc
created_at2023-11-29 01:56:09.080211
updated_at2023-11-29 01:56:09.080211
descriptionMiddlewares support for hypers web framework
homepage
repository
max_upload_size
id1052527
size56,381
(lo-ferris)

documentation

README

⚡️ 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")
}
Commit count: 0

cargo fmt