mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-27 07:19:04 +02:00
align hello-world examples
This commit is contained in:
@ -56,18 +56,19 @@ Code:
|
||||
```rust
|
||||
use actix_web::{get, web, App, HttpServer, Responder};
|
||||
|
||||
#[get("/{id}/{name}/index.html")]
|
||||
async fn index(params: web::Path<(u32, String)>) -> impl Responder {
|
||||
let (id, name) = params.into_inner();
|
||||
format!("Hello {}! id:{}", name, id)
|
||||
#[get("/hello/{name}")]
|
||||
async fn greet(name: web::Path<String>) -> impl Responder {
|
||||
format!("Hello {name}!")
|
||||
}
|
||||
|
||||
#[actix_web::main] // or #[tokio::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
HttpServer::new(|| App::new().service(index))
|
||||
.bind(("127.0.0.1", 8080))?
|
||||
.run()
|
||||
.await
|
||||
HttpServer::new(|| {
|
||||
App::new().service(greet)
|
||||
})
|
||||
.bind(("127.0.0.1", 8080))?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -4,18 +4,19 @@
|
||||
//! ```no_run
|
||||
//! use actix_web::{get, web, App, HttpServer, Responder};
|
||||
//!
|
||||
//! #[get("/{id}/{name}/index.html")]
|
||||
//! async fn index(path: web::Path<(u32, String)>) -> impl Responder {
|
||||
//! let (id, name) = path.into_inner();
|
||||
//! format!("Hello {}! id:{}", name, id)
|
||||
//! #[get("/hello/{name}")]
|
||||
//! async fn greet(name: web::Path<String>) -> impl Responder {
|
||||
//! format!("Hello {}!", name)
|
||||
//! }
|
||||
//!
|
||||
//! #[actix_web::main]
|
||||
//! #[actix_web::main] // or #[tokio::main]
|
||||
//! async fn main() -> std::io::Result<()> {
|
||||
//! HttpServer::new(|| App::new().service(index))
|
||||
//! .bind("127.0.0.1:8080")?
|
||||
//! .run()
|
||||
//! .await
|
||||
//! HttpServer::new(|| {
|
||||
//! App::new().service(greet)
|
||||
//! })
|
||||
//! .bind(("127.0.0.1", 8080))?
|
||||
//! .run()
|
||||
//! .await
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
|
Reference in New Issue
Block a user