#![cfg(not(test))]
use actix_web::{post, web::Json, App, HttpResponse, HttpServer, Responder};
use actix_web_validation::Validated;
use serde::{Deserialize, Serialize};
use validator::Validate;
#[derive(Debug, Serialize, Deserialize, Validate)]
struct Example {
#[validate(length(min = 5))]
name: String,
}
#[post("/example")]
async fn example(Validated(Json(payload)): Validated<Json<Example>>) -> impl Responder {
println!("Got validated payload {:#?}", payload);
HttpResponse::Ok().body(format!("Hello {}", payload.name))
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| App::new().service(example))
.bind(("127.0.0.1", 8080))?
.run()
.await
}