1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-07-03 20:45:46 +00: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

@ -1,4 +1,4 @@
.PHONY: default build test doc clean
.PHONY: default build test doc book clean
CARGO_FLAGS := --features "$(FEATURES)"
@ -20,3 +20,7 @@ clippy:
doc: build
cargo doc --no-deps $(CARGO_FLAGS)
cd guide; mdbook build -d ../target/doc/guide/; cd ..
book:
cd guide; mdbook build -d ../target/doc/guide/; cd ..

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!")
}
```