cognitox 0.1.2

AWS Cognito User Pools emulator for local development
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use serde::{Serialize, de::DeserializeOwned};
use serde_json::Value;

use crate::error::{AppError, Result};

/// Deserialize request payload into a typed request.
pub fn parse_request<T: DeserializeOwned>(body: Value) -> Result<T> {
    serde_json::from_value(body)
        .map_err(|e| AppError::InvalidParameter(format!("Invalid request: {}", e)))
}

/// Serialize typed response into Cognito JSON payload.
pub fn to_response_value<T: Serialize>(response: T) -> Result<Value> {
    serde_json::to_value(response).map_err(|e| AppError::Internal(format!("Invalid response: {e}")))
}