Deleting resources using the DELETE method
DELETE methods are like GET methods. We could technically pass data in the JSON body of the HTTP request, there should be enough data in the URL that we can perform a delete. In our case, the title of the item is enough to delete the item from storage.
Before we define the core and server functions, we must ensure that our data access layer function returns the right message if we do not find the right item when deleting from our store. Some slight refactoring is needed where we return the right error if there was no item found in the store with the following code:
//! File: nanoservices/to_do/dal/src/json_file.rs
pub fn delete_one<T>(id: &str) -> Result<(), NanoServiceError>
where
T: Serialize + DeserializeOwned + Clone + std::fmt::Debug,
{
let mut tasks = get_all::<T>().unwrap_or(HashMap::new());
match tasks.remove(id) {
Some(_) => {
save_all(&tasks)?;
Ok(())
...