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

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))?