From a313315a92c358e882b5224498d3200c9eee5cae Mon Sep 17 00:00:00 2001 From: Cameron Dershem Date: Sun, 16 Jun 2019 20:19:25 -0400 Subject: [PATCH] begin url-dispatch chapter. --- examples/url-dispatch/Cargo.toml | 1 + examples/url-dispatch/src/main.rs | 14 +++----------- examples/url-dispatch/src/path2.rs | 6 +++--- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/examples/url-dispatch/Cargo.toml b/examples/url-dispatch/Cargo.toml index 0602c8e..7cabeff 100644 --- a/examples/url-dispatch/Cargo.toml +++ b/examples/url-dispatch/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "url-dispatch" version = "0.7.0" +edition = "2018" workspace = "../" [dependencies] diff --git a/examples/url-dispatch/src/main.rs b/examples/url-dispatch/src/main.rs index 38b76a2..f6d5391 100644 --- a/examples/url-dispatch/src/main.rs +++ b/examples/url-dispatch/src/main.rs @@ -1,10 +1,3 @@ -extern crate actix; -extern crate actix_web; -extern crate futures; -extern crate openssl; -#[macro_use] -extern crate serde; - mod cfg; mod dhandler; mod minfo; @@ -17,12 +10,11 @@ mod pred; mod pred2; mod resource; mod scope; -mod scope; mod url_ext; mod urls; //
-use actix_web::{http::Method, App, HttpRequest, HttpResponse}; +use actix_web::{web, App, HttpRequest, HttpResponse}; fn index(req: HttpRequest) -> HttpResponse { unimplemented!() @@ -30,8 +22,8 @@ fn index(req: HttpRequest) -> HttpResponse { fn main() { App::new() - .route("/user/{name}", Method::GET, index) - .route("/user/{name}", Method::POST, index) + .route("/user/{name}", web::get().to(index)) + .route("/user/{name}", web::get().to(index)) .finish(); } //
diff --git a/examples/url-dispatch/src/path2.rs b/examples/url-dispatch/src/path2.rs index 6f2aea6..b433e1f 100644 --- a/examples/url-dispatch/src/path2.rs +++ b/examples/url-dispatch/src/path2.rs @@ -1,6 +1,6 @@ // -extern crate serde_derive; -use actix_web::{http::Method, App, Path, Result}; +use actix_web::{http::Method, web, App, Result}; +use serde::Deserialize; #[derive(Deserialize)] struct Info { @@ -8,7 +8,7 @@ struct Info { } // extract path info using serde -fn index(info: Path) -> Result { +fn index(info: web::Path) -> Result { Ok(format!("Welcome {}!", info.username)) }