#[derive(Debug, Clone)]
pub struct MyCtx;
#[cfg(feature = "axum")]
#[tokio::main]
async fn main() {
use httpz::{
http::{Method, Response, StatusCode},
GenericEndpoint, Request,
};
let endpoint = GenericEndpoint::new(
"/*any",
[Method::GET, Method::POST],
|req: Request| async move {
let _axum_state = req.get_axum_state::<MyCtx>().unwrap();
Ok(Response::builder()
.status(StatusCode::OK)
.header("Content-Type", "text/html")
.body(b"Hello httpz World!".to_vec())?)
},
);
let app = axum::Router::<MyCtx>::new()
.nest("/", endpoint.axum())
.with_state(MyCtx {});
let addr = "[::]:9000".parse::<std::net::SocketAddr>().unwrap(); println!("Axum listening on http://{}", addr);
axum::Server::bind(&addr)
.serve(app.into_make_service())
.await
.unwrap();
}