diff --git a/content/docs/url-dispatch.md b/content/docs/url-dispatch.md index 8a5c873..17edd50 100644 --- a/content/docs/url-dispatch.md +++ b/content/docs/url-dispatch.md @@ -407,24 +407,24 @@ with `App::service()` method. {{< include-example example="url-dispatch" file="dhandler.rs" section="default" >}} [handlersection]: ../handlers/ -[approute]: https://docs.rs/actix-web/1.0.2/actix_web/struct.App.html#method.route -[appservice]: https://docs.rs/actix-web/1.0.2/actix_web/struct.App.html?search=#method.service -[webresource]: https://docs.rs/actix-web/1.0.2/actix_web/struct.Resource.html -[resourcehandler]: https://docs.rs/actix-web/1.0.2/actix_web/struct.Resource.html#method.route -[route]: https://docs.rs/actix-web/1.0.2/actix_web/struct.Route.html -[routeguard]: https://docs.rs/actix-web/1.0.2/actix_web/struct.Route.html#method.guard -[routemethod]: https://docs.rs/actix-web/1.0.2/actix_web/struct.Route.html#method.method -[routeto]: https://docs.rs/actix-web/1.0.2/actix_web/struct.Route.html#method.to -[routetoasync]: https://docs.rs/actix-web/1.0.2/actix_web/struct.Route.html#method.to_async -[matchinfo]: https://docs.rs/actix-web/1.0.2/actix_web/struct.HttpRequest.html#method.match_info -[pathget]: https://docs.rs/actix-web/1.0.2/actix_web/dev/struct.Path.html#method.get -[pathstruct]: https://docs.rs/actix-web/1.0.2/actix_web/dev/struct.Path.html -[query]: https://docs.rs/actix-web/1.0.2/actix_web/web/struct.Query.html -[urlfor]: https://docs.rs/actix-web/1.0.2/actix_web/struct.HttpRequest.html#method.url_for +[approute]: https://docs.rs/actix-web/2/actix_web/struct.App.html#method.route +[appservice]: https://docs.rs/actix-web/2/actix_web/struct.App.html?search=#method.service +[webresource]: https://docs.rs/actix-web/2/actix_web/struct.Resource.html +[resourcehandler]: https://docs.rs/actix-web/2/actix_web/struct.Resource.html#method.route +[route]: https://docs.rs/actix-web/2/actix_web/struct.Route.html +[routeguard]: https://docs.rs/actix-web/2/actix_web/struct.Route.html#method.guard +[routemethod]: https://docs.rs/actix-web/2/actix_web/struct.Route.html#method.method +[routeto]: https://docs.rs/actix-web/2/actix_web/struct.Route.html#method.to +[routetoasync]: https://docs.rs/actix-web/2/actix_web/struct.Route.html#method.to_async +[matchinfo]: https://docs.rs/actix-web/2/actix_web/struct.HttpRequest.html#method.match_info +[pathget]: https://docs.rs/actix-web/2/actix_web/dev/struct.Path.html#method.get +[pathstruct]: https://docs.rs/actix-web/2/actix_web/dev/struct.Path.html +[query]: https://docs.rs/actix-web/2/actix_web/web/struct.Query.html +[urlfor]: https://docs.rs/actix-web/2/actix_web/struct.HttpRequest.html#method.url_for [urlobj]: https://docs.rs/url/1.7.2/url/struct.Url.html -[guardtrait]: https://docs.rs/actix-web/1.0.2/actix_web/guard/trait.Guard.html -[guardfuncs]: https://docs.rs/actix-web/1.0.2/actix_web/guard/index.html#functions -[requestextensions]: https://docs.rs/actix-web/1.0.2/actix_web/struct.HttpRequest.html#method.extensions -[implfromrequest]: https://docs.rs/actix-web/1.0.2/actix_web/trait.FromRequest.html -[implresponder]: https://docs.rs/actix-web/1.0.2/actix_web/trait.Responder.html +[guardtrait]: https://docs.rs/actix-web/2/actix_web/guard/trait.Guard.html +[guardfuncs]: https://docs.rs/actix-web/2/actix_web/guard/index.html#functions +[requestextensions]: https://docs.rs/actix-web/2/actix_web/struct.HttpRequest.html#method.extensions +[implfromrequest]: https://docs.rs/actix-web/2/actix_web/trait.FromRequest.html +[implresponder]: https://docs.rs/actix-web/2/actix_web/trait.Responder.html [pathextractor]: ../extractors diff --git a/examples/url-dispatch/Cargo.toml b/examples/url-dispatch/Cargo.toml index b7914ca..dbd9149 100644 --- a/examples/url-dispatch/Cargo.toml +++ b/examples/url-dispatch/Cargo.toml @@ -5,8 +5,9 @@ edition = "2018" workspace = "../" [dependencies] -actix = "0.8" -actix-web = "1.0" -futures = "0.1" +actix = "0.9" +actix-rt = "1.0" +actix-web = "2.0" +futures = "0.3.1" openssl = "0.10" serde = "1.0" diff --git a/examples/url-dispatch/src/cfg.rs b/examples/url-dispatch/src/cfg.rs index dfad2cd..21381bd 100644 --- a/examples/url-dispatch/src/cfg.rs +++ b/examples/url-dispatch/src/cfg.rs @@ -1,7 +1,8 @@ use actix_web::{guard, web, App, HttpResponse}; #[rustfmt::skip] -pub fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { use actix_web::HttpServer; HttpServer::new(|| { @@ -16,8 +17,7 @@ App::new().service( ) // }) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await } diff --git a/examples/url-dispatch/src/dhandler.rs b/examples/url-dispatch/src/dhandler.rs index e67891a..dad5c07 100644 --- a/examples/url-dispatch/src/dhandler.rs +++ b/examples/url-dispatch/src/dhandler.rs @@ -1,11 +1,12 @@ use actix_web::{guard, web, App, HttpRequest, HttpResponse, HttpServer, Responder}; -fn index(_req: HttpRequest) -> impl Responder { +async fn index(_req: HttpRequest) -> impl Responder { "Welcome!" } // -pub fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { HttpServer::new(|| { App::new() .service(web::resource("/").route(web::get().to(index))) @@ -15,9 +16,8 @@ pub fn main() { .to(|| HttpResponse::MethodNotAllowed()), ) }) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await } // diff --git a/examples/url-dispatch/src/guard.rs b/examples/url-dispatch/src/guard.rs index 1ef5d6b..48eddbf 100644 --- a/examples/url-dispatch/src/guard.rs +++ b/examples/url-dispatch/src/guard.rs @@ -9,7 +9,8 @@ impl Guard for ContentTypeHeader { } } -pub fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { use actix_web::{web, App, HttpServer}; HttpServer::new(|| { @@ -20,9 +21,8 @@ pub fn main() { .to(|| HttpResponse::Ok()), ) }) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await } // diff --git a/examples/url-dispatch/src/guard2.rs b/examples/url-dispatch/src/guard2.rs index 2d3d30b..bef0407 100644 --- a/examples/url-dispatch/src/guard2.rs +++ b/examples/url-dispatch/src/guard2.rs @@ -1,7 +1,8 @@ // use actix_web::{guard, web, App, HttpResponse, HttpServer}; -pub fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { HttpServer::new(|| { App::new().route( "/", @@ -10,9 +11,8 @@ pub fn main() { .to(|| HttpResponse::MethodNotAllowed()), ) }) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await } // diff --git a/examples/url-dispatch/src/main.rs b/examples/url-dispatch/src/main.rs index 009b26a..85b61e7 100644 --- a/examples/url-dispatch/src/main.rs +++ b/examples/url-dispatch/src/main.rs @@ -16,19 +16,19 @@ pub mod urls; //
use actix_web::{web, App, HttpResponse, HttpServer}; -fn index() -> HttpResponse { +async fn index() -> HttpResponse { HttpResponse::Ok().body("Hello") } -fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { HttpServer::new(|| { App::new() .route("/", web::get().to(index)) .route("/user", web::post().to(index)) }) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await } //
diff --git a/examples/url-dispatch/src/minfo.rs b/examples/url-dispatch/src/minfo.rs index 7c993d7..16dc037 100644 --- a/examples/url-dispatch/src/minfo.rs +++ b/examples/url-dispatch/src/minfo.rs @@ -1,14 +1,15 @@ // use actix_web::{HttpRequest, HttpResponse, Result}; -fn index(req: HttpRequest) -> Result { +async fn index(req: HttpRequest) -> Result { let v1: u8 = req.match_info().get("v1").unwrap().parse().unwrap(); let v2: u8 = req.match_info().query("v2").parse().unwrap(); let (v3, v4): (u8, u8) = req.match_info().load().unwrap(); Ok(format!("Values {} {} {} {}", v1, v2, v3, v4)) } -pub fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { use actix_web::{web, App, HttpServer}; HttpServer::new(|| { @@ -16,9 +17,8 @@ pub fn main() { .route("/a/{v1}/{v2}/", web::get().to(index)) .route("", web::get().to(|| HttpResponse::Ok())) }) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await } // diff --git a/examples/url-dispatch/src/norm.rs b/examples/url-dispatch/src/norm.rs index 4d1abf7..12c27aa 100644 --- a/examples/url-dispatch/src/norm.rs +++ b/examples/url-dispatch/src/norm.rs @@ -1,11 +1,12 @@ // use actix_web::{middleware, HttpResponse}; -fn index() -> HttpResponse { +async fn index() -> HttpResponse { HttpResponse::Ok().body("Hello") } -pub fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { use actix_web::{web, App, HttpServer}; HttpServer::new(|| { @@ -13,9 +14,8 @@ pub fn main() { .wrap(middleware::NormalizePath) .route("/resource/", web::to(index)) }) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await } // diff --git a/examples/url-dispatch/src/norm2.rs b/examples/url-dispatch/src/norm2.rs index a704fa7..c4cc7d5 100644 --- a/examples/url-dispatch/src/norm2.rs +++ b/examples/url-dispatch/src/norm2.rs @@ -7,16 +7,16 @@ fn index() -> HttpResponse { // use actix_web::{http::Method, middleware, web, App, HttpServer}; -pub fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { HttpServer::new(|| { App::new() .wrap(middleware::NormalizePath) .route("/resource/", web::get().to(index)) .default_service(web::route().method(Method::GET)) }) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await } // diff --git a/examples/url-dispatch/src/path.rs b/examples/url-dispatch/src/path.rs index 11e2a99..81a6359 100644 --- a/examples/url-dispatch/src/path.rs +++ b/examples/url-dispatch/src/path.rs @@ -1,11 +1,12 @@ // use actix_web::{web, Result}; -fn index(info: web::Path<(String, u32)>) -> Result { +async fn index(info: web::Path<(String, u32)>) -> Result { Ok(format!("Welcome {}! id: {}", info.0, info.1)) } -pub fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { use actix_web::{App, HttpServer}; HttpServer::new(|| { @@ -14,9 +15,8 @@ pub fn main() { web::get().to(index), ) }) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await } // diff --git a/examples/url-dispatch/src/path2.rs b/examples/url-dispatch/src/path2.rs index 799a412..7cd60a4 100644 --- a/examples/url-dispatch/src/path2.rs +++ b/examples/url-dispatch/src/path2.rs @@ -8,11 +8,12 @@ struct Info { } // extract path info using serde -fn index(info: web::Path) -> Result { +async fn index(info: web::Path) -> Result { Ok(format!("Welcome {}!", info.username)) } -pub fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { use actix_web::{App, HttpServer}; HttpServer::new(|| { @@ -21,9 +22,8 @@ pub fn main() { web::get().to(index), ) }) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await } // diff --git a/examples/url-dispatch/src/pbuf.rs b/examples/url-dispatch/src/pbuf.rs index 36b7e7c..5b037bd 100644 --- a/examples/url-dispatch/src/pbuf.rs +++ b/examples/url-dispatch/src/pbuf.rs @@ -2,18 +2,18 @@ use actix_web::{HttpRequest, Result}; use std::path::PathBuf; -fn index(req: HttpRequest) -> Result { +async fn index(req: HttpRequest) -> Result { let path: PathBuf = req.match_info().query("tail").parse().unwrap(); Ok(format!("Path {:?}", path)) } -pub fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { use actix_web::{web, App, HttpServer}; HttpServer::new(|| App::new().route(r"/a/{tail:.*}", web::get().to(index))) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await } // diff --git a/examples/url-dispatch/src/scope.rs b/examples/url-dispatch/src/scope.rs index 11ac91e..ba4677e 100644 --- a/examples/url-dispatch/src/scope.rs +++ b/examples/url-dispatch/src/scope.rs @@ -1,15 +1,16 @@ use actix_web::{web, App, HttpResponse, HttpServer}; // -fn show_users() -> HttpResponse { +async fn show_users() -> HttpResponse { HttpResponse::Ok().body("Show users") } -fn user_detail(path: web::Path<(u32,)>) -> HttpResponse { +async fn user_detail(path: web::Path<(u32,)>) -> HttpResponse { HttpResponse::Ok().body(format!("User detail: {}", path.0)) } -pub fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { HttpServer::new(|| { App::new().service( web::scope("/users") @@ -17,9 +18,8 @@ pub fn main() { .route("/show/{id}", web::get().to(user_detail)), ) }) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await } // diff --git a/examples/url-dispatch/src/url_ext.rs b/examples/url-dispatch/src/url_ext.rs index 7de8e6e..0d9ec9a 100644 --- a/examples/url-dispatch/src/url_ext.rs +++ b/examples/url-dispatch/src/url_ext.rs @@ -1,14 +1,15 @@ // use actix_web::{HttpRequest, Responder}; -fn index(req: HttpRequest) -> impl Responder { +async fn index(req: HttpRequest) -> impl Responder { let url = req.url_for("youtube", &["oHg5SJYRHA0"]).unwrap(); assert_eq!(url.as_str(), "https://youtube.com/watch/oHg5SJYRHA0"); url.into_string() } -pub fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { use actix_web::{web, App, HttpServer}; HttpServer::new(|| { @@ -17,9 +18,8 @@ pub fn main() { .external_resource("youtube", "https://youtube.com/watch/{video_id}") .route("/", actix_web::web::get().to(index)) }) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await } // diff --git a/examples/url-dispatch/src/urls.rs b/examples/url-dispatch/src/urls.rs index 8fc03fb..66ec903 100644 --- a/examples/url-dispatch/src/urls.rs +++ b/examples/url-dispatch/src/urls.rs @@ -1,7 +1,7 @@ // use actix_web::{guard, http::header, HttpRequest, HttpResponse, Result}; -fn index(req: HttpRequest) -> Result { +async fn index(req: HttpRequest) -> Result { let url = req.url_for("foo", &["1", "2", "3"])?; // <- generate url for "foo" resource Ok(HttpResponse::Found() @@ -9,7 +9,8 @@ fn index(req: HttpRequest) -> Result { .finish()) } -pub fn main() { +#[actix_rt::main] +async fn main() -> std::io::Result<()> { use actix_web::{web, App, HttpServer}; HttpServer::new(|| { @@ -22,9 +23,8 @@ pub fn main() { ) .route("/test/", web::get().to(index)) }) - .bind("127.0.0.1:8088") - .unwrap() + .bind("127.0.0.1:8088")? .run() - .unwrap(); + .await } //