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

Change method from GET to POST (#277)

Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
Ovidiu Gheorghies 2022-07-30 20:19:42 +03:00 committed by GitHub
parent 50d9694c81
commit 779f8ea83e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,5 @@
// <json-one> // <json-one>
use actix_web::{get, web, App, HttpServer, Result}; use actix_web::{post, web, App, HttpServer, Result};
use serde::Deserialize; use serde::Deserialize;
#[derive(Deserialize)] #[derive(Deserialize)]
@ -8,15 +8,15 @@ struct Info {
} }
/// deserialize `Info` from request's body /// deserialize `Info` from request's body
#[get("/")] #[post("/submit")]
async fn index(info: web::Json<Info>) -> Result<String> { async fn submit(info: web::Json<Info>) -> Result<String> {
Ok(format!("Welcome {}!", info.username)) Ok(format!("Welcome {}!", info.username))
} }
// </json-one> // </json-one>
#[actix_web::main] #[actix_web::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
HttpServer::new(|| App::new().service(index)) HttpServer::new(|| App::new().service(submit))
.bind(("127.0.0.1", 8080))? .bind(("127.0.0.1", 8080))?
.run() .run()
.await .await