mirror of
https://github.com/actix/actix-web.git
synced 2025-01-08 16:25:29 +00:00
more guide
This commit is contained in:
parent
987b275c3f
commit
6f5b58b691
3 changed files with 36 additions and 7 deletions
6
Makefile
6
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 ..
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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!")
|
||||
}
|
||||
```
|
||||
|
|
Loading…
Reference in a new issue