1
0
mirror of https://github.com/actix/actix-website synced 2024-11-23 16:31:08 +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>
use actix_web::{get, web, App, HttpServer, Result};
use actix_web::{post, web, App, HttpServer, Result};
use serde::Deserialize;
#[derive(Deserialize)]
@ -8,15 +8,15 @@ struct Info {
}
/// deserialize `Info` from request's body
#[get("/")]
async fn index(info: web::Json<Info>) -> Result<String> {
#[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(index))
HttpServer::new(|| App::new().service(submit))
.bind(("127.0.0.1", 8080))?
.run()
.await