Updating resources using the PUT method
PUT methods are essentially the same as a POST method. We want to put the data in the JSON body. However, the PUT method is typically used for updating resources that have already been created. This is the last endpoint that we create in this chapter. Here, we must accept a to-do item in the JSON body, get the item, and update it. This is a good point to try and build the API endpoint yourself.
If you tried to build your own API endpoint, hopefully you started with the core function. First, we import the following:
//! File: nanoservices/to_do/core/src/basic_actions/update.rs
use dal::json_file::{
get_all as get_all_handle,
save_all
};
use crate::structs::ToDoItem;
use glue::errors::{
NanoServiceError,
NanoServiceErrorStatus
};
And with these imports we define the update function with the code below:
//! File: nanoservices/to_do/core/src/basic_actions/update.rs
pub async fn update(item: ToDoItem)
-> Result<(), NanoServiceError...