From f657be7ae5c8ac51505dfca5c9d55ae529729281 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sat, 26 May 2018 14:27:55 +0200 Subject: [PATCH] Added routing example to frontpage --- layouts/index.html | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/layouts/index.html b/layouts/index.html index 4a1d6c6..37fc768 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -117,6 +117,28 @@ struct Register { fn register(data: Form) -> impl Responder { format!("Hello {} from {}!", data.username, data.country) +}` "rust" "" }} + +
+

Request Routing

+

+ An actix app comes with a URL routing system that lets you match on + URLs and invoke individual handlers. For extra flexibility scopes + can be used. +

+ {{ highlight `fn index(req: HttpRequest) -> impl Responder { + "Hello from the index page" +} + +fn hello(req: HttpRequest) -> impl Responder { + format!("Hello {}!", req.match_info().get("name").unwrap()) +} + +fn main() { + App::new() + .resource("/", |r| r.method(Method::Get).with(index)) + .resource("/hello/{name}", |r| r.method(Method::Get).with(hello)) + .finish(); }` "rust" "" }}
@@ -125,6 +147,7 @@ fn register(data: Form) -> impl Responder {
  • flexible responders
  • powerful extractors
  • easy form handling +
  • request routing