1
0
mirror of https://github.com/actix/actix-website synced 2025-02-02 12:19:04 +01:00

28 lines
581 B
Rust
Raw Normal View History

pub mod manual;
pub mod multipart;
pub mod streaming;
pub mod urlencoded;
2019-06-26 01:27:17 -04:00
2019-06-17 14:34:23 -04:00
// <json-request>
2019-06-26 01:27:17 -04:00
use actix_web::{web, App, HttpServer, Result};
2019-06-17 14:34:23 -04:00
use serde::Deserialize;
#[derive(Deserialize)]
struct Info {
username: String,
}
/// extract `Info` using serde
2019-12-29 02:32:47 +09:00
async fn index(info: web::Json<Info>) -> Result<String> {
2019-06-17 14:34:23 -04:00
Ok(format!("Welcome {}!", info.username))
}
2020-09-12 16:21:54 +01:00
#[actix_web::main]
2019-12-29 02:32:47 +09:00
async fn main() -> std::io::Result<()> {
2019-06-26 01:27:17 -04:00
HttpServer::new(|| App::new().route("/", web::post().to(index)))
2022-02-26 03:56:24 +00:00
.bind(("127.0.0.1", 8080))?
2019-06-26 01:27:17 -04:00
.run()
2019-12-29 02:32:47 +09:00
.await
2019-06-17 14:34:23 -04:00
}
// </json-request>