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

24 lines
518 B
Rust
Raw Normal View History

2019-06-16 23:17:17 -04:00
// <json-one>
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
#[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]
async fn main() -> std::io::Result<()> {
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()
.await
2019-06-16 23:17:17 -04:00
}