1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-25 06:39:22 +02:00

more guide

This commit is contained in:
Nikolay Kim
2017-11-28 18:00:10 -08:00
parent 987b275c3f
commit 6f5b58b691
3 changed files with 36 additions and 7 deletions

View File

@ -27,7 +27,7 @@ actix-web = { git = "https://github.com/actix/actix-web" }
In order to implement a web server, first we need to create a request handler.
A request handler is a function that accepts a `HttpRequest` instance as its only parameter
and returns a `HttpResponse` instance or actor that uses `HttpContext` as an actor's context::
and returns a type that can be converted into `HttpResponse`:
```rust,ignore
extern crate actix_web;

View File

@ -71,8 +71,33 @@ fn main() {
## Handler
A request handler can have several different forms. Simple function
that accepts `HttpRequest` and returns `HttpResponse` or any type that can be converted
into `HttpResponse`. Function that that accepts `HttpRequest` and
returns `Stream<Item=Frame, Error=Error>`. Or http actor, i.e. actor that has `HttpContext<A>`
as a context.
A request handler can have several different forms.
* Simple function that accepts `HttpRequest` and returns `HttpResponse` or any
type that can be converted into `HttpResponse`.
* Function that that accepts `HttpRequest` and returns `Stream<Item=Frame, Error=Error>`.
* Http actor, i.e. actor that has `HttpContext<A>`as a context.
Actix provides response conversion for some standard types, like `&'static str`, `String`, etc.
For complete list of implementations check
[HttpResponse documentation](../actix_web/struct.HttpResponse.html#implementations).
Examples:
```rust,ignore
fn index(req: HttpRequest) -> &'static str {
"Hello world!"
}
```
```rust,ignore
fn index(req: HttpRequest) -> String {
"Hello world!".to_owned()
}
```
```rust,ignore
fn index(req: HttpRequest) -> Bytes {
Bytes::from_static("Hello world!")
}
```