mirror of
https://github.com/fafhrd91/actix-web
synced 2025-01-18 05:41:50 +01:00
cleanup more examples
This commit is contained in:
parent
406d2c41e9
commit
0a68811dce
@ -37,7 +37,6 @@ struct State {
|
||||
fn index(req: HttpRequest<State>) -> Box<Future<Item=HttpResponse, Error=Error>> {
|
||||
let name = &req.match_info()["name"];
|
||||
|
||||
Box::new(
|
||||
req.state().db.call_fut(CreateUser{name: name.to_owned()})
|
||||
.from_err()
|
||||
.and_then(|res| {
|
||||
@ -45,7 +44,8 @@ fn index(req: HttpRequest<State>) -> Box<Future<Item=HttpResponse, Error=Error>>
|
||||
Ok(user) => Ok(httpcodes::HTTPOk.build().json(user)?),
|
||||
Err(_) => Ok(httpcodes::HTTPInternalServerError.response())
|
||||
}
|
||||
}))
|
||||
})
|
||||
.responder()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -107,16 +107,16 @@ used for async handler registration.
|
||||
fn index(req: HttpRequest<State>) -> Box<Future<Item=HttpResponse, Error=Error>> {
|
||||
let name = &req.match_info()["name"];
|
||||
|
||||
Box::new(
|
||||
// Send message to `DbExecutor` actor
|
||||
req.state().db.call_fut(CreateUser{name: name.to_owned()})
|
||||
.from_err()
|
||||
.and_then(|res| {
|
||||
match res {
|
||||
Ok(user) => ok(HTTPOk.build().json(user)),
|
||||
Err(_) => ok(HTTPInternalServerError.response())
|
||||
Ok(user) => Ok(httpcodes::HTTPOk.build().json(user)?),
|
||||
Err(_) => Ok(httpcodes::HTTPInternalServerError.response())
|
||||
}
|
||||
})
|
||||
.map_err(|e| error::ErrorInternalServerError(e).into()))
|
||||
.responder()
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -234,14 +234,13 @@ use actix_web::*;
|
||||
use futures::future::{Future, ok};
|
||||
|
||||
fn index(mut req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>> {
|
||||
Box::new(
|
||||
req.urlencoded() // <- get UrlEncoded future
|
||||
.from_err()
|
||||
.and_then(|params| { // <- url encoded parameters
|
||||
println!("==== BODY ==== {:?}", params);
|
||||
ok(httpcodes::HTTPOk.response())
|
||||
})
|
||||
.map_err(Error::from)
|
||||
)
|
||||
.responder()
|
||||
}
|
||||
# fn main() {}
|
||||
```
|
||||
@ -276,15 +275,15 @@ use futures::{Future, Stream};
|
||||
|
||||
|
||||
fn index(mut req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>> {
|
||||
Box::new(
|
||||
req.payload_mut()
|
||||
.readany()
|
||||
.from_err()
|
||||
.fold((), |_, chunk| {
|
||||
println!("Chunk: {:?}", chunk);
|
||||
result::<_, error::PayloadError>(Ok(()))
|
||||
})
|
||||
.map_err(|e| Error::from(e))
|
||||
.map(|_| HttpResponse::Ok().finish().unwrap()))
|
||||
.map(|_| HttpResponse::Ok().finish().unwrap())
|
||||
.responder()
|
||||
}
|
||||
# fn main() {}
|
||||
```
|
||||
|
@ -456,14 +456,13 @@ impl<S> HttpRequest<S> {
|
||||
/// use futures::future::{Future, ok};
|
||||
///
|
||||
/// fn index(mut req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>> {
|
||||
/// Box::new(
|
||||
/// req.urlencoded() // <- get UrlEncoded future
|
||||
/// .from_err()
|
||||
/// .and_then(|params| { // <- url encoded parameters
|
||||
/// println!("==== BODY ==== {:?}", params);
|
||||
/// ok(httpcodes::HTTPOk.response())
|
||||
/// })
|
||||
/// .map_err(Error::from)
|
||||
/// )
|
||||
/// .responder()
|
||||
/// }
|
||||
/// # fn main() {}
|
||||
/// ```
|
||||
|
Loading…
x
Reference in New Issue
Block a user