mirror of
https://github.com/actix/examples
synced 2024-11-27 16:02:57 +01:00
Fix examples of diesel and json (#207)
This commit is contained in:
parent
998f92d2e3
commit
5ffbaacdce
@ -60,8 +60,7 @@ async fn add(
|
|||||||
|
|
||||||
/// This handler manually parse json object. Bytes object supports FromRequest trait (extractor)
|
/// This handler manually parse json object. Bytes object supports FromRequest trait (extractor)
|
||||||
/// and could be loaded from request payload automatically
|
/// and could be loaded from request payload automatically
|
||||||
async fn index_add(body: Bytes, pool: web::Data<Pool>) -> Result<HttpResponse, Error> {
|
async fn index_add(body: web::Bytes, pool: web::Data<Pool>) -> Result<HttpResponse, Error> {
|
||||||
let mut body = BytesMut::new();
|
|
||||||
// body is loaded, now we can deserialize id with serde-json
|
// body is loaded, now we can deserialize id with serde-json
|
||||||
let r_obj = serde_json::from_slice::<MyUser>(&body);
|
let r_obj = serde_json::from_slice::<MyUser>(&body);
|
||||||
|
|
||||||
|
@ -6,8 +6,9 @@ workspace = ".."
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "2.0.0-alpha.3"
|
actix-web = "2.0.0-alpha.4"
|
||||||
actix-rt = "1.0.0-alpha.3"
|
actix-rt = "1.0.0-alpha.3"
|
||||||
|
actix-service = "1.0.0-alpha.4"
|
||||||
|
|
||||||
bytes = "0.5.2"
|
bytes = "0.5.2"
|
||||||
futures = "0.3.1"
|
futures = "0.3.1"
|
||||||
|
@ -90,10 +90,12 @@ mod tests {
|
|||||||
use actix_web::dev::Service;
|
use actix_web::dev::Service;
|
||||||
use actix_web::{http, test, web, App};
|
use actix_web::{http, test, web, App};
|
||||||
|
|
||||||
#[test]
|
#[actix_rt::test]
|
||||||
fn test_index() -> Result<(), Error> {
|
async fn test_index() -> Result<(), Error> {
|
||||||
let app = App::new().route("/", web::post().to(index));
|
let mut app = test::init_service(
|
||||||
let mut app = test::init_service(app);
|
App::new().service(web::resource("/").route(web::post().to(index))),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
let req = test::TestRequest::post()
|
let req = test::TestRequest::post()
|
||||||
.uri("/")
|
.uri("/")
|
||||||
@ -102,7 +104,7 @@ mod tests {
|
|||||||
number: 43,
|
number: 43,
|
||||||
})
|
})
|
||||||
.to_request();
|
.to_request();
|
||||||
let resp = test::block_on(app.call(req)).unwrap();
|
let resp = app.call(req).await.unwrap();
|
||||||
|
|
||||||
assert_eq!(resp.status(), http::StatusCode::OK);
|
assert_eq!(resp.status(), http::StatusCode::OK);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user