I am experimenting with tide and glommio using Rust. Consider following code:
use std::io::Result;
use glommio::prelude::*;
use tide::Request;
use tide::Response;
use tide::http::mime;
use tide::prelude::*;
#[async_std::main]
async fn main() -> Result<()> {
let mut app = tide::new();
app.at("/orders/shoes").post(order_shoes);
let builder = LocalExecutorPoolBuilder::new(16);
let handles = builder.on_all_shards(|| async move {
app.listen("127.0.0.1:8080").await;
}).unwrap();
handles.join_all();
Ok(())
}
#[derive(Debug, Deserialize)]
struct Animal {
name: String,
legs: u8,
}
pub async fn order_shoes(mut req: Request<()>) -> tide::Result {
let Animal { name, legs } = req.body_json().await?;
let res = Response::builder(203)
.body("Hi")
.header("custom-header", "value")
.content_type(mime::HTML)
.build();
Ok(res)
}
Now in case the request has legs greater than 255 then it should respond with error but I am unable to figure out how to return that to caller.