mirror of
https://github.com/zigzap/zap.git
synced 2025-10-21 15:44:10 +00:00
29 lines
881 B
Rust
29 lines
881 B
Rust
use axum::{routing::get, Router};
|
|
use std::net::SocketAddr;
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
// Route all requests on "/" endpoint to anonymous handler.
|
|
//
|
|
// A handler is an async function which returns something that implements
|
|
// `axum::response::IntoResponse`.
|
|
|
|
// A closure or a function can be used as handler.
|
|
|
|
let app = Router::new().route("/", get(handler));
|
|
// Router::new().route("/", get(|| async { "Hello, world!" }));
|
|
|
|
// Address that server will bind to.
|
|
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
|
|
|
|
// Use `hyper::server::Server` which is re-exported through `axum::Server` to serve the app.
|
|
axum::Server::bind(&addr)
|
|
// Hyper server takes a make service.
|
|
.serve(app.into_make_service())
|
|
.await
|
|
.unwrap();
|
|
}
|
|
|
|
async fn handler() -> &'static str {
|
|
"Hello from axum!!"
|
|
}
|