Passing data into our views
In order to create a to-do item, follow these steps:
- We need to pass the parameters of the item that we are creating into a view with an auth token as a POST method. Then, we can decode the token that matches the outcome. If the decoding results in an error, we return a rejection. If the token is correctly decoded, we can continue inserting the new to-do item. This process can be defined by using the
make_item_reply
function, as shown here:async fn make_item_reply(token: String, item: ToDoItem) -> Result<Box<dyn warp::Reply>, warp::Rejection> { Â Â Â Â match our_jwt::JwtToken::decode(token) { Â Â Â Â Â Â Â Â Ok(token) => { Â Â Â Â Â Â Â Â Â Â Â Â . . . Â Â Â Â Â Â Â Â }, Â Â Â Â Â Â Â Â Err(_message) => { Â Â Â Â Â Â Â Â Â Â Â ...