Skip to main content

lambda_forge/
response.rs

1use serde::{Deserialize, Serialize};
2use serde_json::{Value, json};
3
4#[derive(Serialize, Deserialize)]
5#[serde(rename_all = "camelCase")]
6pub struct ApiResponseBody<T> {
7    pub was_successful: bool,
8    pub data: Option<T>,
9    pub message: Option<String>,
10}
11impl ApiResponseBody<Value> {
12    /// Parse an [`ApiResponse`] into a JSON body string.
13    pub fn into_json_body(self) -> String {
14        json!({
15            "wasSuccessful": self.was_successful,
16            "data": self.data,
17            "message": self.message,
18        })
19        .to_string()
20    }
21}