forked from http-rs/tide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
- Loading branch information
1 parent
6665925
commit 37d9ff0
Showing
2 changed files
with
26 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use async_std::task; | ||
use serde::{Serialize, Deserialize}; | ||
|
||
#[derive(Deserialize, Serialize)] | ||
struct Cat { | ||
name: String | ||
} | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> { | ||
task::block_on(async { | ||
let app = tide::new(); | ||
|
||
app.at("/submit").post(|req: tide::Request<()>| async { | ||
let cat: Cat = req.body_json().await.unwrap(); | ||
println!("cat name: {}", cat.name); | ||
|
||
let cat = Cat { name: "chashu".into() }; | ||
let res = tide::Response::new(200).body_json(&cat).unwrap(); | ||
res | ||
}); | ||
|
||
app.listen("127.0.0.1:8080").await?; | ||
Ok(()) | ||
}) | ||
} |