mirror of
https://github.com/actix/actix-website
synced 2025-02-22 20:23:18 +01:00
updates Getting Started.
This commit is contained in:
parent
d762e83e74
commit
471d21b618
@ -27,18 +27,17 @@ actix-web = "{{< actix-version "actix-web" >}}"
|
|||||||
|
|
||||||
In order to implement a web server, we first need to create a request handler.
|
In order to implement a web server, we first need to create a request handler.
|
||||||
|
|
||||||
A request handler is a function that accepts an `HttpRequest` instance as its only parameter
|
A request handler is a function that accepts any type that can be extracted from a
|
||||||
and returns a type that can be converted into `HttpResponse`:
|
request (ie, `impl FromRequest`) as its only parameter and returns a type that
|
||||||
|
can be converted into an `HttpResponse` (ie, `impl Responder`):
|
||||||
Filename: `src/main.rs`
|
|
||||||
|
|
||||||
{{< include-example example="getting-started" section="setup" >}}
|
{{< include-example example="getting-started" section="setup" >}}
|
||||||
|
|
||||||
Next, create an `Application` instance and register the request handler with
|
Next, create an `App` instance and register the request handler with
|
||||||
the application's `resource` on a particular *HTTP method* and *path* and
|
the application's `route` on a particular *HTTP method* and *path* and
|
||||||
after that, the application instance can be used with `HttpServer` to listen
|
after that, the application instance can be used with `HttpServer` to listen
|
||||||
for incoming connections. The server accepts a function that should return an
|
for incoming connections. The server accepts a function that should return an
|
||||||
`HttpResponse`.
|
application factory.
|
||||||
|
|
||||||
{{< include-example example="getting-started" section="main" >}}
|
{{< include-example example="getting-started" section="main" >}}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "getting-started"
|
name = "getting-started"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
|
edition = "2018"
|
||||||
workspace = "../"
|
workspace = "../"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
// <setup>
|
// <setup>
|
||||||
extern crate actix_web;
|
use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, Responder};
|
||||||
use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer};
|
|
||||||
|
|
||||||
fn index(_req: HttpRequest) -> HttpResponse {
|
fn index(_req: HttpRequest) -> impl Responder {
|
||||||
HttpResponse::Ok().body("Hello world!")
|
HttpResponse::Ok().body("Hello world!")
|
||||||
}
|
}
|
||||||
// </setup>
|
// </setup>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user