6 releases

0.0.6 Oct 13, 2023
0.0.5 Jul 17, 2023
0.0.4 Mar 5, 2023
0.0.3 Sep 29, 2022

#245 in HTTP server

Download history 429/week @ 2023-11-02 186/week @ 2023-11-09 856/week @ 2023-11-16 742/week @ 2023-11-23 750/week @ 2023-11-30 404/week @ 2023-12-07 486/week @ 2023-12-14 297/week @ 2023-12-21 371/week @ 2023-12-28 505/week @ 2024-01-04 207/week @ 2024-01-11 275/week @ 2024-01-18 262/week @ 2024-01-25 137/week @ 2024-02-01 178/week @ 2024-02-08 152/week @ 2024-02-15

776 downloads per month
Used in rspc

MIT license

58KB
1K SLoC

httpz

Code once, support every Rust webserver!

Discord Crates.io License

This project is a 🚧 work in progress 🚧. Currently it is designed around the goals of rspc but feel free to reach to me if you want to collaborate on using it in your own project.

Usage

    // Define your a single HTTP handler which is supported by all major Rust webservers.
let endpoint = GenericEndpoint::new(
    // Set URL prefix
    "/",
    // Set the supported HTTP methods
    [Method::GET, Method::POST],
    // Define the handler function
    |_req: Request| async move {
        Ok(Response::builder()
            .status(StatusCode::OK)
            .header("Content-Type", "text/html")
            .body(b"Hello httpz World!".to_vec())?)
    },
);

// Attach your generic endpoint to Axum
let app = axum::Router::new().route("/", endpoint.axum());

// Attach your generic endpoint to Actix Web
HttpServer::new({
    let endpoint = endpoint.actix();
    move || App::new().service(web::scope("/prefix").service(endpoint.mount()))
});

// and so on...

Check out the rest of the examples!

Features

  • Write your HTTP handler once and support Axum, Actix Web, Poem, Rocket, Warp and more.
  • Support for websockets on compatible webservers.

Projects using httpz

httpz is primarily designed to make life easier for library authors. It allows a library author to write and test a HTTP endpoint once and know it will work for all major Rust HTTP servers.

Libraries using httpz:

If you are interested in using httpz and have questions jump in the Discord!

Dependencies

~4–58MB
~846K SLoC