Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oscartbeaumont/httpz
Code once, support every Rust webserver!
https://github.com/oscartbeaumont/httpz
actix-web axum http httpz poem rocket rust rust-http warp
Last synced: about 2 months ago
JSON representation
Code once, support every Rust webserver!
- Host: GitHub
- URL: https://github.com/oscartbeaumont/httpz
- Owner: oscartbeaumont
- License: mit
- Archived: true
- Created: 2022-07-31T08:25:28.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-30T06:07:53.000Z (11 months ago)
- Last Synced: 2024-09-21T12:02:33.986Z (about 2 months ago)
- Topics: actix-web, axum, http, httpz, poem, rocket, rust, rust-http, warp
- Language: Rust
- Homepage:
- Size: 97.7 KB
- Stars: 28
- Watchers: 2
- Forks: 4
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
This project is a 🚧 work in progress 🚧. Currently it is designed around the goals of [rspc](https://rspc.otbeaumont.me) but feel free to reach to me if you want to collaborate on using it in your own project.
## Usage
```rust
// 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](/examples)!
## Features- Write your HTTP handler once and support [Axum](https://github.com/tokio-rs/axum), [Actix Web](https://actix.rs/), [Poem](https://github.com/poem-web/poem), [Rocket](https://rocket.rs), [Warp](https://github.com/seanmonstar/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:
- [rspc](https://github.com/oscartbeaumont/rspc)
If you are interested in using httpz and have questions jump in [the Discord](https://discord.gg/4V9M5sksw8)!