mirror of
https://github.com/actix/examples
synced 2024-11-23 22:41:07 +01:00
Update json/json to v4 (#489)
This commit is contained in:
parent
5df5bd10ea
commit
c2b5d89ea6
6
Cargo.lock
generated
6
Cargo.lock
generated
@ -3215,10 +3215,8 @@ checksum = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd"
|
|||||||
name = "json-example"
|
name = "json-example"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-rt 1.1.1",
|
"actix-web 4.0.0-beta.21",
|
||||||
"actix-service 1.0.6",
|
"env_logger 0.9.0",
|
||||||
"actix-web 3.3.3",
|
|
||||||
"env_logger 0.8.4",
|
|
||||||
"futures",
|
"futures",
|
||||||
"json",
|
"json",
|
||||||
"serde 1.0.136",
|
"serde 1.0.136",
|
||||||
|
@ -5,13 +5,9 @@ authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "3"
|
actix-web = "4.0.0-beta.21"
|
||||||
actix-service = "1.0.0"
|
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
env_logger = "0.8"
|
env_logger = "0.9.0"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
json = "0.12"
|
json = "0.12"
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
actix-rt = "1"
|
|
||||||
|
@ -67,11 +67,11 @@ async fn main() -> std::io::Result<()> {
|
|||||||
App::new()
|
App::new()
|
||||||
// enable logger
|
// enable logger
|
||||||
.wrap(middleware::Logger::default())
|
.wrap(middleware::Logger::default())
|
||||||
.data(web::JsonConfig::default().limit(4096)) // <- limit size of the payload (global configuration)
|
.app_data(web::JsonConfig::default().limit(4096)) // <- limit size of the payload (global configuration)
|
||||||
.service(web::resource("/extractor").route(web::post().to(index)))
|
.service(web::resource("/extractor").route(web::post().to(index)))
|
||||||
.service(
|
.service(
|
||||||
web::resource("/extractor2")
|
web::resource("/extractor2")
|
||||||
.data(web::JsonConfig::default().limit(1024)) // <- limit size of the payload (resource level)
|
.app_data(web::JsonConfig::default().limit(1024)) // <- limit size of the payload (resource level)
|
||||||
.route(web::post().to(extract_item)),
|
.route(web::post().to(extract_item)),
|
||||||
)
|
)
|
||||||
.service(web::resource("/manual").route(web::post().to(index_manual)))
|
.service(web::resource("/manual").route(web::post().to(index_manual)))
|
||||||
@ -86,12 +86,13 @@ async fn main() -> std::io::Result<()> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use actix_web::body::to_bytes;
|
||||||
use actix_web::dev::Service;
|
use actix_web::dev::Service;
|
||||||
use actix_web::{http, test, web, App};
|
use actix_web::{http, test, web, App};
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_web::test]
|
||||||
async fn test_index() -> Result<(), Error> {
|
async fn test_index() {
|
||||||
let mut app = test::init_service(
|
let app = test::init_service(
|
||||||
App::new().service(web::resource("/").route(web::post().to(index))),
|
App::new().service(web::resource("/").route(web::post().to(index))),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
@ -107,13 +108,7 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(resp.status(), http::StatusCode::OK);
|
assert_eq!(resp.status(), http::StatusCode::OK);
|
||||||
|
|
||||||
let response_body = match resp.response().body().as_ref() {
|
let body_bytes = to_bytes(resp.into_body()).await.unwrap();
|
||||||
Some(actix_web::body::Body::Bytes(bytes)) => bytes,
|
assert_eq!(body_bytes, r##"{"name":"my-name","number":43}"##);
|
||||||
_ => panic!("Response error"),
|
|
||||||
};
|
|
||||||
|
|
||||||
assert_eq!(response_body, r##"{"name":"my-name","number":43}"##);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user