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)
|
||||
/// and could be loaded from request payload automatically
|
||||
async fn index_add(body: Bytes, pool: web::Data<Pool>) -> Result<HttpResponse, Error> {
|
||||
let mut body = BytesMut::new();
|
||||
async fn index_add(body: web::Bytes, pool: web::Data<Pool>) -> Result<HttpResponse, Error> {
|
||||
// body is loaded, now we can deserialize id with serde-json
|
||||
let r_obj = serde_json::from_slice::<MyUser>(&body);
|
||||
|
||||
|
@ -6,8 +6,9 @@ workspace = ".."
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "2.0.0-alpha.3"
|
||||
actix-web = "2.0.0-alpha.4"
|
||||
actix-rt = "1.0.0-alpha.3"
|
||||
actix-service = "1.0.0-alpha.4"
|
||||
|
||||
bytes = "0.5.2"
|
||||
futures = "0.3.1"
|
||||
|
@ -90,10 +90,12 @@ mod tests {
|
||||
use actix_web::dev::Service;
|
||||
use actix_web::{http, test, web, App};
|
||||
|
||||
#[test]
|
||||
fn test_index() -> Result<(), Error> {
|
||||
let app = App::new().route("/", web::post().to(index));
|
||||
let mut app = test::init_service(app);
|
||||
#[actix_rt::test]
|
||||
async fn test_index() -> Result<(), Error> {
|
||||
let mut app = test::init_service(
|
||||
App::new().service(web::resource("/").route(web::post().to(index))),
|
||||
)
|
||||
.await;
|
||||
|
||||
let req = test::TestRequest::post()
|
||||
.uri("/")
|
||||
@ -102,7 +104,7 @@ mod tests {
|
||||
number: 43,
|
||||
})
|
||||
.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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user