2019-06-16 23:17:17 -04:00
|
|
|
// <json-one>
|
2022-07-30 20:19:42 +03:00
|
|
|
use actix_web::{post, web, App, HttpServer, Result};
|
2019-06-16 23:17:17 -04:00
|
|
|
use serde::Deserialize;
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
struct Info {
|
|
|
|
username: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// deserialize `Info` from request's body
|
2022-07-30 20:19:42 +03:00
|
|
|
#[post("/submit")]
|
|
|
|
async fn submit(info: web::Json<Info>) -> Result<String> {
|
2019-06-16 23:17:17 -04:00
|
|
|
Ok(format!("Welcome {}!", info.username))
|
|
|
|
}
|
2019-06-20 04:20:12 -04:00
|
|
|
// </json-one>
|
2019-06-16 23:17:17 -04:00
|
|
|
|
2020-09-12 16:21:54 +01:00
|
|
|
#[actix_web::main]
|
2019-12-28 16:26:17 +01:00
|
|
|
async fn main() -> std::io::Result<()> {
|
2022-07-30 20:19:42 +03:00
|
|
|
HttpServer::new(|| App::new().service(submit))
|
2022-02-26 03:56:24 +00:00
|
|
|
.bind(("127.0.0.1", 8080))?
|
2019-06-20 04:20:12 -04:00
|
|
|
.run()
|
2019-12-28 16:26:17 +01:00
|
|
|
.await
|
2019-06-16 23:17:17 -04:00
|
|
|
}
|