Extracting data from views
In this section, we are going to explore extracting data from our HTTP requests from the header and body. We are then going to use these methods to edit, delete to-do items, and intercept requests before they are fully loaded with middleware. We will go one step at a time. For now, let us extract data from the body of the HTTP request to edit a to-do item. When it comes to accepting data in JSON format, we should do what we have been doing throughout the book, separating this code from the view. If we think about it, we just need to send in the item that we are editing. However, we can also use this same schema for deleting. We can define our schema in our json_serialization/to_do_item.rs
file with the following code:
use serde::Deserialize; #[derive(Deserialize)] pub struct ToDoItem { pub title: String, pub status: String }
In the preceding code, we have merely stated which type of data we need for each...