2019-06-16 23:17:17 -04:00
|
|
|
// <json-one>
|
2020-09-12 16:21:54 +01:00
|
|
|
use actix_web::{get, 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
|
2020-09-12 16:21:54 +01:00
|
|
|
#[get("/")]
|
2019-12-28 16:26:17 +01:00
|
|
|
async fn index(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<()> {
|
2020-09-12 16:21:54 +01:00
|
|
|
HttpServer::new(|| App::new().service(index))
|
|
|
|
.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
|
|
|
}
|