mirror of
https://github.com/actix/actix-website
synced 2025-02-13 00:25:35 +01:00
24 lines
505 B
Rust
24 lines
505 B
Rust
// <json-one>
|
|
use actix_web::{get, web, App, HttpServer, Result};
|
|
use serde::Deserialize;
|
|
|
|
#[derive(Deserialize)]
|
|
struct Info {
|
|
username: String,
|
|
}
|
|
|
|
/// deserialize `Info` from request's body
|
|
#[get("/")]
|
|
async fn index(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(index))
|
|
.bind("127.0.0.1:8080")?
|
|
.run()
|
|
.await
|
|
}
|