1
0
mirror of https://github.com/actix/actix-website synced 2025-06-29 08:14:58 +02:00

begin update of docs to actix-web 1.0

This commit is contained in:
Cameron Dershem
2019-06-12 04:51:45 -04:00
parent ad45f9e95a
commit 8aa39e1afb
9 changed files with 43 additions and 24 deletions

View File

@ -39,23 +39,23 @@
</div>
<div class="col-md-8">
<div class="actix-content">
{{ highlight `extern crate actix_web;
use actix_web::{server, App, HttpRequest, Responder};
{{ highlight `use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer};
fn greet(req: &HttpRequest) -> impl Responder {
let to = req.match_info().get("name").unwrap_or("World");
format!("Hello {}!", to)
fn greet(req: HttpRequest) -> HttpResponse {
let name = req.match_info().get("name").unwrap_or("World");
HttpResponse::Ok().body(format!("Hello {}!", &name))
}
fn main() {
server::new(|| {
HttpServer::new(|| {
App::new()
.resource("/", |r| r.f(greet))
.resource("/{name}", |r| r.f(greet))
.service(web::resource("/").to(greet))
.service(web::resource("/{name}").to(greet))
})
.bind("127.0.0.1:8000")
.expect("Can not bind to port 8000")
.run();
.run()
.unwrap();
}` "rust" "" }}
</div>
</div>