1
0
mirror of https://github.com/actix/actix-website synced 2025-02-08 22:36:07 +01:00
Ovidiu Gheorghies 779f8ea83e
Change method from GET to POST (#277)
Co-authored-by: Rob Ede <robjtede@icloud.com>
2022-07-30 18:19:42 +01:00

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
}