1
0
mirror of https://github.com/actix/actix-website synced 2024-12-18 01:43:59 +01:00

Added routing example to frontpage

This commit is contained in:
Armin Ronacher 2018-05-26 14:27:55 +02:00
parent fd51870371
commit f657be7ae5

View File

@ -117,6 +117,28 @@ struct Register {
fn register(data: Form<Register>) -> impl Responder {
format!("Hello {} from {}!", data.username, data.country)
}` "rust" "" }}
</div>
<div class="actix-feature" id="routing">
<h2>Request Routing</h2>
<p>
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.
</p>
{{ 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" "" }}
</div>
</div>
@ -125,6 +147,7 @@ fn register(data: Form<Register>) -> impl Responder {
<li class="actix-feature-selector"><a href="#responders">flexible responders</label>
<li class="actix-feature-selector"><a href="#extractors">powerful extractors</label>
<li class="actix-feature-selector"><a href="#forms">easy form handling</label>
<li class="actix-feature-selector"><a href="#routing">request routing</label>
</ul>
</div>
</div>