Crates.io | httpz |
lib.rs | httpz |
version | 0.0.6 |
source | src |
created_at | 2022-09-24 07:09:38.397584 |
updated_at | 2023-10-13 15:24:13.086724 |
description | Code once, support every Rust webserver! |
homepage | https://github.com/oscartbeaumont/httpz |
repository | https://github.com/oscartbeaumont/httpz |
max_upload_size | |
id | 672920 |
size | 203,444 |
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.
// 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!
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!