mirror of
https://github.com/actix/actix-website
synced 2024-11-24 00:41:07 +01:00
begin update of docs to actix-web 1.0
This commit is contained in:
parent
ad45f9e95a
commit
8aa39e1afb
@ -16,4 +16,4 @@ baseURL = "https://actix.rs"
|
||||
|
||||
[params]
|
||||
actixVersion = "0.7"
|
||||
actixWebVersion = "0.7"
|
||||
actixWebVersion = "1.0"
|
||||
|
@ -27,6 +27,7 @@ actix-web = "{{< actix-version "actix-web" >}}"
|
||||
|
||||
In order to implement a web server, we first need to create a request handler.
|
||||
|
||||
<!-- TODO: Handler has been deprecated -->
|
||||
A request handler is a function that accepts an `HttpRequest` instance as its only parameter
|
||||
and returns a type that can be converted into `HttpResponse`:
|
||||
|
||||
@ -34,12 +35,12 @@ Filename: `src/main.rs`
|
||||
|
||||
{{< include-example example="getting-started" section="setup" >}}
|
||||
|
||||
<!-- TODO: Return ->
|
||||
Next, create an `Application` instance and register the request handler with
|
||||
the application's `resource` on a particular *HTTP method* and *path* and
|
||||
after that, the application instance can be used with `HttpServer` to listen
|
||||
for incoming connections. The server accepts a function that should return an
|
||||
`HttpHandler` instance. For simplicity `server::new` could be used, this
|
||||
function is shortcut for `HttpServer::new`:
|
||||
`HttpResponse`.
|
||||
|
||||
{{< include-example example="getting-started" section="main" >}}
|
||||
|
||||
|
@ -9,7 +9,7 @@ weight: 110
|
||||
Since `actix-web` is a Rust framework you will need Rust to get started with it.
|
||||
If you don't have it yet we recommend you use `rustup` to manage your Rust
|
||||
installation. The [official rust
|
||||
guide](https://doc.rust-lang.org/book/second-edition/ch01-01-installation.html)
|
||||
guide](https://doc.rust-lang.org/book/ch01-01-installation.html)
|
||||
has a wonderful section on getting started.
|
||||
|
||||
We currently require at least Rust 1.24 so make sure you run `rustup update`
|
||||
@ -18,7 +18,7 @@ guide will assume that you actually run Rust 1.26 or later.
|
||||
|
||||
# Installing `actix-web`
|
||||
|
||||
Thank's to Rust's `cargo` package manager you won't need to explicitly install
|
||||
Thanks to Rust's `cargo` package manager you won't need to explicitly install
|
||||
`actix-web`. Just depend on it and you're ready to go. For the unlikely
|
||||
case that you want to use the development version of actix-web you can
|
||||
depend on the git repository directly.
|
||||
|
@ -4,4 +4,4 @@ version = "0.7.0"
|
||||
workspace = "../"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "0.7"
|
||||
actix-web = "1.0"
|
||||
|
@ -4,4 +4,4 @@ version = "0.7.0"
|
||||
workspace = "../"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "0.7"
|
||||
actix-web = "1.0"
|
||||
|
@ -1,16 +1,34 @@
|
||||
// // <setup>
|
||||
// extern crate actix_web;
|
||||
// use actix_web::{server, App, HttpRequest};
|
||||
|
||||
// fn index(_req: &HttpRequest) -> &'static str {
|
||||
// "Hello world!"
|
||||
// }
|
||||
// // </setup>
|
||||
// // <main>
|
||||
// fn main() {
|
||||
// server::new(|| App::new().resource("/", |r| r.f(index)))
|
||||
// .bind("127.0.0.1:8088")
|
||||
// .unwrap()
|
||||
// .run();
|
||||
// }
|
||||
// // </main>
|
||||
|
||||
// <setup>
|
||||
extern crate actix_web;
|
||||
use actix_web::{server, App, HttpRequest};
|
||||
use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer};
|
||||
|
||||
fn index(_req: &HttpRequest) -> &'static str {
|
||||
"Hello world!"
|
||||
fn index(_req: HttpRequest) -> HttpResponse {
|
||||
HttpResponse::Ok().body("Hello world!")
|
||||
}
|
||||
// </setup>
|
||||
// <main>
|
||||
fn main() {
|
||||
server::new(|| App::new().resource("/", |r| r.f(index)))
|
||||
.bind("127.0.0.1:8088")
|
||||
HttpServer::new(|| App::new().service(web::resource("/").to(index)))
|
||||
.bind("127.0.0.1:8000")
|
||||
.unwrap()
|
||||
.run();
|
||||
.run()
|
||||
.unwrap();
|
||||
}
|
||||
// </main>
|
||||
|
@ -5,6 +5,6 @@ workspace = "../"
|
||||
|
||||
[dependencies]
|
||||
actix = "0.7"
|
||||
actix-web = { version="0.7", features=["alpn"] }
|
||||
actix-web = "1.0"
|
||||
futures = "0.1"
|
||||
openssl = "0.10"
|
||||
|
@ -5,7 +5,7 @@ workspace = "../"
|
||||
|
||||
[dependencies]
|
||||
actix = "0.7"
|
||||
actix-web = "0.7"
|
||||
actix-web = "1.0"
|
||||
futures = "0.1"
|
||||
openssl = "0.10"
|
||||
serde = "1.0"
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user