success

Function success 

Source
pub fn success<T>(data: T) -> ApiResponse<T>
Expand description

Creates a successful API response by wrapping data in Json and Ok.

This helper function simplifies the creation of successful API responses by automatically wrapping the provided data in both Json and Ok. It’s particularly useful in route handlers where you want to return successful responses with less boilerplate.

§Arguments

  • data - The data to be returned in the response. This can be any type that implements serialization traits required by axum::Json.

§Returns

Returns an ApiResponse<T> containing the wrapped data.

§Examples

use skyak_axum_core::https::{ApiResponse, success};

// Simple success response with a string
async fn handle_string() -> ApiResponse<String> {
    success("Hello, world!".to_string())
}

// Success response with a complex type
#[derive(serde::Serialize)]
struct User {
    id: i32,
    name: String,
}

async fn handle_user() -> ApiResponse<User> {
    let user = User {
        id: 1,
        name: "Alice".to_string(),
    };
    success(user)
}