2021-08-18 00:49:01 +02:00
|
|
|
//! Run with
|
|
|
|
|
//!
|
|
|
|
|
//! ```not_rust
|
2022-04-29 18:53:41 +02:00
|
|
|
//! cd examples && cargo run -p example-hello-world
|
2021-08-18 00:49:01 +02:00
|
|
|
//! ```
|
|
|
|
|
|
2021-11-02 13:07:34 +01:00
|
|
|
use axum::{response::Html, routing::get, Router};
|
|
|
|
|
use std::net::SocketAddr;
|
|
|
|
|
|
2021-08-18 00:49:01 +02:00
|
|
|
#[tokio::main]
|
|
|
|
|
async fn main() {
|
2021-11-02 13:07:34 +01:00
|
|
|
// build our application with a route
|
|
|
|
|
let app = Router::new().route("/", get(handler));
|
2021-08-18 00:49:01 +02:00
|
|
|
|
2021-11-02 13:07:34 +01:00
|
|
|
// run it
|
|
|
|
|
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
|
|
|
|
|
println!("listening on {}", addr);
|
|
|
|
|
axum::Server::bind(&addr)
|
2021-08-18 00:49:01 +02:00
|
|
|
.serve(app.into_make_service())
|
|
|
|
|
.await
|
|
|
|
|
.unwrap();
|
|
|
|
|
}
|
2021-11-02 13:07:34 +01:00
|
|
|
|
|
|
|
|
async fn handler() -> Html<&'static str> {
|
|
|
|
|
Html("<h1>Hello, World!</h1>")
|
|
|
|
|
}
|