Passing parameters via the URL
Passing parameters via the URL is the easiest way to pass data to the server. We can explore this concept by passing the name of a to-do item and returning that single to-do item to the client.
Before we touch the networking layer, we must build the core function that loads the data and filters for the to-do item by name which can be done with the following code:
//! File: nanoservices/to_do/core/src/api/basic_actions/get.rs
. . .
use glue::errors::{
NanoServiceError,
NanoServiceErrorStatus
};
. . .
pub async fn get_by_name(name: &str)
-> Result<ToDoItem, NanoServiceError> {
Ok(get_all_handle::<ToDoItem>()?
.remove(name)
.ok_or(
NanoServiceError::new(
format!("Item with name {} not found", name),
NanoServiceErrorStatus::NotFound
)
)?
)
}
Note that our filter at this stage is not optional, as we are loading all the data and then...