mirror of
https://github.com/actix/actix-website
synced 2025-02-08 22:36:07 +01:00
24 lines
518 B
Rust
24 lines
518 B
Rust
// <json-one>
|
|
use actix_web::{post, web, App, HttpServer, Result};
|
|
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> {
|
|
Ok(format!("Welcome {}!", info.username))
|
|
}
|
|
// </json-one>
|
|
|
|
#[actix_web::main]
|
|
async fn main() -> std::io::Result<()> {
|
|
HttpServer::new(|| App::new().service(submit))
|
|
.bind(("127.0.0.1", 8080))?
|
|
.run()
|
|
.await
|
|
}
|