add json route

This commit is contained in:
2023-10-29 19:01:13 -03:00
parent d5d2ab4956
commit 77aa085b0c
7 changed files with 94 additions and 16 deletions

62
ActixAPI/Cargo.lock generated
View File

@@ -8,8 +8,11 @@ version = "0.1.0"
dependencies = [
"actix-files",
"actix-web",
"futures",
"magick_rust",
"qstring",
"serde",
"serde_json",
]
[[package]]
@@ -549,12 +552,65 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "futures"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40"
dependencies = [
"futures-channel",
"futures-core",
"futures-executor",
"futures-io",
"futures-sink",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-channel"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2"
dependencies = [
"futures-core",
"futures-sink",
]
[[package]]
name = "futures-core"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c"
[[package]]
name = "futures-executor"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0"
dependencies = [
"futures-core",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-io"
version = "0.3.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa"
[[package]]
name = "futures-macro"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.32",
]
[[package]]
name = "futures-sink"
version = "0.3.28"
@@ -573,10 +629,16 @@ version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533"
dependencies = [
"futures-channel",
"futures-core",
"futures-io",
"futures-macro",
"futures-sink",
"futures-task",
"memchr",
"pin-project-lite",
"pin-utils",
"slab",
]
[[package]]

View File

@@ -10,3 +10,6 @@ actix-web = "4"
actix-files = "0.6.2"
magick_rust = "0.19.1"
qstring = "0.7.2"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1"
futures = "0.3"

View File

@@ -5,7 +5,7 @@ use magick_rust::MagickWand;
#[get("/status/ok")]
async fn hello() -> impl Responder {
HttpResponse::Ok().body("{\"status\": 200}")
HttpResponse::Ok()
}
async fn static_serve(req: HttpRequest) -> Result<NamedFile> {
@@ -29,6 +29,17 @@ async fn simulation_harmonic_progression(req: HttpRequest) -> impl Responder {
HttpResponse::Ok().body(format!("{}", sum))
}
#[get("/simulation/json")]
async fn simulation_json() -> impl Responder {
// body = {"message": "Hello World"}
let body = serde_json::json!({
"message": "Hello World!"
});
HttpResponse::Ok()
.json(body)
}
#[get("/image/load-small-image")]
async fn load_small_image() -> Result<NamedFile> {
let real_path = "static/small-image.png";
@@ -89,6 +100,7 @@ async fn main() -> std::io::Result<()> {
.service(save_big_image)
.service(blur_image)
.service(simulation_harmonic_progression)
.service(simulation_json)
.app_data(web::PayloadConfig::new(1024 * 1024 * 1024))
})
.bind(("0.0.0.0", 5000))?