mirror of
https://github.com/actix/actix-website
synced 2024-11-27 10:02:57 +01:00
Change method from GET to POST (#277)
Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
parent
50d9694c81
commit
779f8ea83e
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user