From 6f5b58b6914800202b5dac8599edc2ab6d985b80 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 28 Nov 2017 18:00:10 -0800 Subject: [PATCH] more guide --- Makefile | 6 +++++- guide/src/qs_2.md | 2 +- guide/src/qs_3.md | 35 ++++++++++++++++++++++++++++++----- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index c6a6cbd0a..fc6071083 100644 --- a/Makefile +++ b/Makefile @@ -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 .. diff --git a/guide/src/qs_2.md b/guide/src/qs_2.md index 44bb84e36..b3727b580 100644 --- a/guide/src/qs_2.md +++ b/guide/src/qs_2.md @@ -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; diff --git a/guide/src/qs_3.md b/guide/src/qs_3.md index 64419071f..43f9265ea 100644 --- a/guide/src/qs_3.md +++ b/guide/src/qs_3.md @@ -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`. Or http actor, i.e. actor that has `HttpContext` -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`. +* Http actor, i.e. actor that has `HttpContext`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!") +} +```