Adding get by unique ID to networking
When it comes to passing a unique ID to our networking layer, we can just use our header token, our token stores the unique ID. This enables us to securely call the API endpoint from the client, or just pass the token to the auth server from the to-do server. Our auth get endpoint can be defined with the code below:
// nanoservices/auth/networking/actix_server/src/api/users/get.rs
use auth_dal::users::transactions::get::GetByUniqueId;
use auth_core::api::users::get::get_by_unique_id
as get_by_unique_id_core;
use glue::errors::NanoServiceError;
use glue::token::HeaderToken;
use actix_web::HttpResponse;
pub async fn get_by_unique_id<T: GetByUniqueId>(token: HeaderToken)
-> Result<HttpResponse, NanoServiceError> {
let user = get_by_unique_id_core::<T>(token.unique_id).await?;
Ok(HttpResponse::Ok().json(user))
}
We can then mount the endpoint to the server with our Postgres handler with the following code:
// nanoservices...