mirror of
https://github.com/actix/actix-website
synced 2024-11-27 18:12:57 +01:00
begin url-dispatch chapter.
This commit is contained in:
parent
5bd4218b94
commit
a313315a92
@ -1,6 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "url-dispatch"
|
name = "url-dispatch"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
|
edition = "2018"
|
||||||
workspace = "../"
|
workspace = "../"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -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 cfg;
|
||||||
mod dhandler;
|
mod dhandler;
|
||||||
mod minfo;
|
mod minfo;
|
||||||
@ -17,12 +10,11 @@ mod pred;
|
|||||||
mod pred2;
|
mod pred2;
|
||||||
mod resource;
|
mod resource;
|
||||||
mod scope;
|
mod scope;
|
||||||
mod scope;
|
|
||||||
mod url_ext;
|
mod url_ext;
|
||||||
mod urls;
|
mod urls;
|
||||||
|
|
||||||
// <main>
|
// <main>
|
||||||
use actix_web::{http::Method, App, HttpRequest, HttpResponse};
|
use actix_web::{web, App, HttpRequest, HttpResponse};
|
||||||
|
|
||||||
fn index(req: HttpRequest) -> HttpResponse {
|
fn index(req: HttpRequest) -> HttpResponse {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
@ -30,8 +22,8 @@ fn index(req: HttpRequest) -> HttpResponse {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.route("/user/{name}", Method::GET, index)
|
.route("/user/{name}", web::get().to(index))
|
||||||
.route("/user/{name}", Method::POST, index)
|
.route("/user/{name}", web::get().to(index))
|
||||||
.finish();
|
.finish();
|
||||||
}
|
}
|
||||||
// </main>
|
// </main>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// <path>
|
// <path>
|
||||||
extern crate serde_derive;
|
use actix_web::{http::Method, web, App, Result};
|
||||||
use actix_web::{http::Method, App, Path, Result};
|
use serde::Deserialize;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Info {
|
struct Info {
|
||||||
@ -8,7 +8,7 @@ struct Info {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// extract path info using serde
|
// extract path info using serde
|
||||||
fn index(info: Path<Info>) -> Result<String> {
|
fn index(info: web::Path<Info>) -> Result<String> {
|
||||||
Ok(format!("Welcome {}!", info.username))
|
Ok(format!("Welcome {}!", info.username))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user