mirror of
https://github.com/actix/actix-web.git
synced 2024-11-22 17:41:11 +00:00
align hello-world examples
This commit is contained in:
parent
62fbd225bc
commit
8c2fad3164
5 changed files with 22 additions and 20 deletions
|
@ -56,18 +56,19 @@ Code:
|
||||||
```rust
|
```rust
|
||||||
use actix_web::{get, web, App, HttpServer, Responder};
|
use actix_web::{get, web, App, HttpServer, Responder};
|
||||||
|
|
||||||
#[get("/{id}/{name}/index.html")]
|
#[get("/hello/{name}")]
|
||||||
async fn index(params: web::Path<(u32, String)>) -> impl Responder {
|
async fn greet(name: web::Path<String>) -> impl Responder {
|
||||||
let (id, name) = params.into_inner();
|
format!("Hello {name}!")
|
||||||
format!("Hello {}! id:{}", name, id)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_web::main] // or #[tokio::main]
|
#[actix_web::main] // or #[tokio::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
HttpServer::new(|| App::new().service(index))
|
HttpServer::new(|| {
|
||||||
.bind(("127.0.0.1", 8080))?
|
App::new().service(greet)
|
||||||
.run()
|
})
|
||||||
.await
|
.bind(("127.0.0.1", 8080))?
|
||||||
|
.run()
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -4,18 +4,19 @@
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! use actix_web::{get, web, App, HttpServer, Responder};
|
//! use actix_web::{get, web, App, HttpServer, Responder};
|
||||||
//!
|
//!
|
||||||
//! #[get("/{id}/{name}/index.html")]
|
//! #[get("/hello/{name}")]
|
||||||
//! async fn index(path: web::Path<(u32, String)>) -> impl Responder {
|
//! async fn greet(name: web::Path<String>) -> impl Responder {
|
||||||
//! let (id, name) = path.into_inner();
|
//! format!("Hello {}!", name)
|
||||||
//! format!("Hello {}! id:{}", name, id)
|
|
||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//! #[actix_web::main]
|
//! #[actix_web::main] // or #[tokio::main]
|
||||||
//! async fn main() -> std::io::Result<()> {
|
//! async fn main() -> std::io::Result<()> {
|
||||||
//! HttpServer::new(|| App::new().service(index))
|
//! HttpServer::new(|| {
|
||||||
//! .bind("127.0.0.1:8080")?
|
//! App::new().service(greet)
|
||||||
//! .run()
|
//! })
|
||||||
//! .await
|
//! .bind(("127.0.0.1", 8080))?
|
||||||
|
//! .run()
|
||||||
|
//! .await
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
|
|
|
@ -5,7 +5,7 @@ authors = [
|
||||||
"Nikolay Kim <fafhrd91@gmail.com>",
|
"Nikolay Kim <fafhrd91@gmail.com>",
|
||||||
"fakeshadow <24548779@qq.com>",
|
"fakeshadow <24548779@qq.com>",
|
||||||
]
|
]
|
||||||
description = "Async HTTP and WebSocket client library built on the Actix ecosystem"
|
description = "Async HTTP and WebSocket client library"
|
||||||
keywords = ["actix", "http", "framework", "async", "web"]
|
keywords = ["actix", "http", "framework", "async", "web"]
|
||||||
categories = [
|
categories = [
|
||||||
"network-programming",
|
"network-programming",
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! `awc` is a HTTP and WebSocket client library built on the Actix ecosystem.
|
//! `awc` is an asynchronous HTTP and WebSocket client library.
|
||||||
//!
|
//!
|
||||||
//! # Making a GET request
|
//! # Making a GET request
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
|
|
|
@ -160,7 +160,7 @@ where
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
/// `Future` implementation returns error if:
|
/// `Future` implementation returns error if:
|
||||||
/// - content length is greater than [limit](JsonBody::limit) (default: 2 MiB)
|
/// - content length is greater than [limit](ResponseBody::limit) (default: 2 MiB)
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
|
|
Loading…
Reference in a new issue