mirror of
https://github.com/tokio-rs/axum.git
synced 2024-11-22 15:17:18 +01:00
Tweak hello world example
This commit is contained in:
parent
35ab973acb
commit
b4e2750d6a
2 changed files with 6 additions and 10 deletions
|
@ -34,17 +34,15 @@ use tower::make::Shared;
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
// build our application with a single route
|
// build our application with a single route
|
||||||
let app = route("/", get(handler));
|
let app = route("/", get(|request: Request<Body>| async {
|
||||||
|
"Hello, World!"
|
||||||
|
}));
|
||||||
|
|
||||||
// run it with hyper on localhost:3000
|
// run it with hyper on localhost:3000
|
||||||
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
|
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
|
||||||
let server = Server::bind(&addr).serve(Shared::new(app));
|
let server = Server::bind(&addr).serve(Shared::new(app));
|
||||||
server.await.unwrap();
|
server.await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handler(req: Request<Body>) -> &'static str {
|
|
||||||
"Hello, World!"
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Routing
|
## Routing
|
||||||
|
|
|
@ -32,17 +32,15 @@
|
||||||
//! #[tokio::main]
|
//! #[tokio::main]
|
||||||
//! async fn main() {
|
//! async fn main() {
|
||||||
//! // build our application with a single route
|
//! // build our application with a single route
|
||||||
//! let app = route("/", get(handler));
|
//! let app = route("/", get(|request: Request<Body>| async {
|
||||||
|
//! "Hello, World!"
|
||||||
|
//! }));
|
||||||
//!
|
//!
|
||||||
//! // run it with hyper on localhost:3000
|
//! // run it with hyper on localhost:3000
|
||||||
//! let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
|
//! let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
|
||||||
//! let server = Server::bind(&addr).serve(Shared::new(app));
|
//! let server = Server::bind(&addr).serve(Shared::new(app));
|
||||||
//! server.await.unwrap();
|
//! server.await.unwrap();
|
||||||
//! }
|
//! }
|
||||||
//!
|
|
||||||
//! async fn handler(req: Request<Body>) -> &'static str {
|
|
||||||
//! "Hello, World!"
|
|
||||||
//! }
|
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! # Routing
|
//! # Routing
|
||||||
|
|
Loading…
Reference in a new issue