mirror of
https://github.com/actix/examples
synced 2024-11-23 14:31: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"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"actix-rt 1.1.1",
|
||||
"actix-service 1.0.6",
|
||||
"actix-web 3.3.3",
|
||||
"env_logger 0.8.4",
|
||||
"actix-web 4.0.0-beta.21",
|
||||
"env_logger 0.9.0",
|
||||
"futures",
|
||||
"json",
|
||||
"serde 1.0.136",
|
||||
|
@ -5,13 +5,9 @@ authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "3"
|
||||
actix-service = "1.0.0"
|
||||
actix-web = "4.0.0-beta.21"
|
||||
futures = "0.3"
|
||||
env_logger = "0.8"
|
||||
env_logger = "0.9.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
json = "0.12"
|
||||
|
||||
[dev-dependencies]
|
||||
actix-rt = "1"
|
||||
json = "0.12"
|
@ -67,11 +67,11 @@ async fn main() -> std::io::Result<()> {
|
||||
App::new()
|
||||
// enable logger
|
||||
.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("/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)),
|
||||
)
|
||||
.service(web::resource("/manual").route(web::post().to(index_manual)))
|
||||
@ -86,12 +86,13 @@ async fn main() -> std::io::Result<()> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use actix_web::body::to_bytes;
|
||||
use actix_web::dev::Service;
|
||||
use actix_web::{http, test, web, App};
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_index() -> Result<(), Error> {
|
||||
let mut app = test::init_service(
|
||||
#[actix_web::test]
|
||||
async fn test_index() {
|
||||
let app = test::init_service(
|
||||
App::new().service(web::resource("/").route(web::post().to(index))),
|
||||
)
|
||||
.await;
|
||||
@ -107,13 +108,7 @@ mod tests {
|
||||
|
||||
assert_eq!(resp.status(), http::StatusCode::OK);
|
||||
|
||||
let response_body = match resp.response().body().as_ref() {
|
||||
Some(actix_web::body::Body::Bytes(bytes)) => bytes,
|
||||
_ => panic!("Response error"),
|
||||
};
|
||||
|
||||
assert_eq!(response_body, r##"{"name":"my-name","number":43}"##);
|
||||
|
||||
Ok(())
|
||||
let body_bytes = to_bytes(resp.into_body()).await.unwrap();
|
||||
assert_eq!(body_bytes, r##"{"name":"my-name","number":43}"##);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user