Extracting data
Extracting data from the request body is fairly straightforward. All we have to do is define a struct with the attributes we want, and then pass that through as a parameter in the view
function. Then, the data from the request body will be serialized to that schema. We can do this by defining the following struct in our json_serialization/to_do_item.rs
file:
use serde::Deserialize; #[derive(Deserialize)] pub struct ToDoItem { pub title: String, pub status: String }
Here, we have used the Deserialize
macro. Now that we have this, we can start building our edit view in the views/to_do/edit.rs
file. Because the view requires a lot of code, we will be breaking it down into sections. First, we need to import all of the crates that we are going to use:
use actix_web::{web, HttpResponse}; use serde_json::value::Value; use serde_json::Map; use super::utils::return_state; use crate::state::read_file; use crate::to_do:...