1
0
mirror of https://github.com/actix/actix-website synced 2025-02-13 08:32:20 +01:00

24 lines
508 B
Rust
Raw Normal View History

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("/")]
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]
async fn main() -> std::io::Result<()> {
2020-09-12 16:21:54 +01:00
HttpServer::new(|| App::new().service(index))
2022-02-26 03:56:24 +00:00
.bind(("127.0.0.1", 8080))?
2019-06-20 04:20:12 -04:00
.run()
.await
2019-06-16 23:17:17 -04:00
}