mirror of
https://github.com/actix/actix-website
synced 2024-11-27 10:02:57 +01:00
begin url-dispatch chapter.
This commit is contained in:
parent
5bd4218b94
commit
a313315a92
@ -1,6 +1,7 @@
|
||||
[package]
|
||||
name = "url-dispatch"
|
||||
version = "0.7.0"
|
||||
edition = "2018"
|
||||
workspace = "../"
|
||||
|
||||
[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 dhandler;
|
||||
mod minfo;
|
||||
@ -17,12 +10,11 @@ mod pred;
|
||||
mod pred2;
|
||||
mod resource;
|
||||
mod scope;
|
||||
mod scope;
|
||||
mod url_ext;
|
||||
mod urls;
|
||||
|
||||
// <main>
|
||||
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();
|
||||
}
|
||||
// </main>
|
||||
|
@ -1,6 +1,6 @@
|
||||
// <path>
|
||||
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<Info>) -> Result<String> {
|
||||
fn index(info: web::Path<Info>) -> Result<String> {
|
||||
Ok(format!("Welcome {}!", info.username))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user