feat: add tide

This commit is contained in:
2021-04-29 23:14:05 +08:00
parent 2b82801053
commit 813a7d5b2f
3 changed files with 1725 additions and 0 deletions

1684
__web/tide/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

13
__web/tide/Cargo.toml Normal file
View File

@@ -0,0 +1,13 @@
[package]
name = "tide"
version = "0.1.0"
authors = ["Hatter Jiang <jht5945@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tide = "0.16.0"
async-std = { version = "1.8.0", features = ["attributes"] }
serde = { version = "1.0", features = ["derive"] }

28
__web/tide/src/main.rs Normal file
View 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())
}