feat: add tide
This commit is contained in:
28
__web/tide/src/main.rs
Normal file
28
__web/tide/src/main.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use tide::Request;
|
||||
use tide::prelude::*;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Animal {
|
||||
name: String,
|
||||
legs: u8,
|
||||
}
|
||||
|
||||
#[async_std::main]
|
||||
async fn main() -> tide::Result<()> {
|
||||
println!("Listen 127.0.0.1:8080");
|
||||
let mut app = tide::new();
|
||||
|
||||
app.at("*").get(index);
|
||||
app.at("/orders/shoes").post(order_shoes);
|
||||
app.listen("127.0.0.1:8080").await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn index(req: Request<()>) -> tide::Result {
|
||||
Ok(format!("Hello world: {:#?}", req).into())
|
||||
}
|
||||
|
||||
async fn order_shoes(mut req: Request<()>) -> tide::Result {
|
||||
let Animal { name, legs } = req.body_json().await?;
|
||||
Ok(format!("Hello, {}! I've put in an order for {} shoes", name, legs).into())
|
||||
}
|
||||
Reference in New Issue
Block a user