1
0
mirror of https://github.com/actix/actix-website synced 2025-06-27 07:29:02 +02:00

update examples to v4 (#258)

This commit is contained in:
Rob Ede
2022-02-26 03:56:24 +00:00
committed by GitHub
parent 890fea6c23
commit 81dfe300a2
110 changed files with 321 additions and 334 deletions

View File

@ -4,6 +4,6 @@ version = "1.0.0"
edition = "2018"
[dependencies]
actix-web = "3"
actix-web = "4"
serde = "1.0"
serde_json = "1.0"

View File

@ -19,7 +19,7 @@ async fn index(form: web::Form<FormData>) -> Result<String> {
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| App::new().service(index))
.bind("127.0.0.1:8080")?
.bind(("127.0.0.1", 8080))?
.run()
.await
}

View File

@ -17,7 +17,7 @@ async fn index(info: web::Json<Info>) -> Result<String> {
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| App::new().service(index))
.bind("127.0.0.1:8080")?
.bind(("127.0.0.1", 8080))?
.run()
.await
}

View File

@ -21,7 +21,8 @@ async fn main() -> std::io::Result<()> {
.limit(4096)
.error_handler(|err, _req| {
// create custom error response
error::InternalError::from_response(err, HttpResponse::Conflict().finish()).into()
error::InternalError::from_response(err, HttpResponse::Conflict().finish())
.into()
});
App::new().service(
@ -31,7 +32,7 @@ async fn main() -> std::io::Result<()> {
.route(web::post().to(index)),
)
})
.bind("127.0.0.1:8080")?
.bind(("127.0.0.1", 8080))?
.run()
.await
}

View File

@ -46,7 +46,7 @@ async fn main() -> std::io::Result<()> {
.route("/{name}/{id}", web::post().to(index))
.route("/{name}/{id}/extract", web::post().to(extract))
})
.bind("127.0.0.1:8080")?
.bind(("127.0.0.1", 8080))?
.run()
.await
}

View File

@ -8,10 +8,8 @@ struct Info {
}
#[get("/users/{user_id}/{friend}")] // <- define path parameters
async fn index(
web::Path((user_id, friend)): web::Path<(u32, String)>,
query: web::Query<Info>,
) -> String {
async fn index(path: web::Path<(u32, String)>, query: web::Query<Info>) -> String {
let (user_id, friend) = path.into_inner();
format!(
"Welcome {}, friend {}, user_id {}!",
query.username, friend, user_id
@ -23,7 +21,7 @@ async fn main() -> std::io::Result<()> {
use actix_web::{App, HttpServer};
HttpServer::new(|| App::new().service(index))
.bind("127.0.0.1:8080")?
.bind(("127.0.0.1", 8080))?
.run()
.await
}

View File

@ -5,7 +5,8 @@ use actix_web::{get, web, Result};
/// {user_id} - deserializes to a u32
/// {friend} - deserializes to a String
#[get("/users/{user_id}/{friend}")] // <- define path parameters
async fn index(web::Path((user_id, friend)): web::Path<(u32, String)>) -> Result<String> {
async fn index(path: web::Path<(u32, String)>) -> Result<String> {
let (user_id, friend) = path.into_inner();
Ok(format!("Welcome {}, user_id {}!", friend, user_id))
}
@ -14,7 +15,7 @@ async fn main() -> std::io::Result<()> {
use actix_web::{App, HttpServer};
HttpServer::new(|| App::new().service(index))
.bind("127.0.0.1:8080")?
.bind(("127.0.0.1", 8080))?
.run()
.await
}

View File

@ -14,7 +14,7 @@ async fn main() -> std::io::Result<()> {
use actix_web::{App, HttpServer};
HttpServer::new(|| App::new().service(index))
.bind("127.0.0.1:8080")?
.bind(("127.0.0.1", 8080))?
.run()
.await
}

View File

@ -22,7 +22,7 @@ async fn main() -> std::io::Result<()> {
use actix_web::{App, HttpServer};
HttpServer::new(|| App::new().service(index))
.bind("127.0.0.1:8080")?
.bind(("127.0.0.1", 8080))?
.run()
.await
}

View File

@ -18,7 +18,7 @@ async fn index(info: web::Query<Info>) -> String {
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| App::new().service(index))
.bind("127.0.0.1:8080")?
.bind(("127.0.0.1", 8080))?
.run()
.await
}