Crate axum_responses

Crate axum_responses 

Source
Expand description

§axum_responses

Ergonomic response builders for Axum web applications.

This crate provides three main response types that implement IntoResponse:

§Quick Start

use axum_responses::JsonResponse;
use serde_json::json;

// Simple OK response
async fn health() -> JsonResponse {
    JsonResponse::Ok().message("Healthy")
}

// Response with data
async fn get_user() -> JsonResponse {
    JsonResponse::Ok().data(json!({"id": 1, "name": "Alice"}))
}

// Error response
async fn not_found() -> JsonResponse {
    JsonResponse::NotFound().message("User not found")
}

§Final JSON Format

All JSON responses follow this standardized structure:

{
    "code": 200,
    "success": true,
    "message": "Healthy",
    "timestamp": "2023-10-01T12:00:00Z"
    "data": { ... },        // Optional (present using .data())
    "error": { ... }       // Optional (present using .error())
    "errors": [ ... ]     // Optional (present using .errors())
}

Modules§

thiserror

Macros§

response
Creates a JSON response with the specified status code and optional data.

Structs§

File
A builder for creating file download/inline responses.
JsonResponse
A builder for creating standardized JSON HTTP responses.
JsonResponseBody
Represents the JSON body structure of a response. Useful for testing and deserialization.
Redirect
A builder for creating HTTP redirect responses.

Enums§

ContentDisposition
Specifies how the content should be presented to the user.

Derive Macros§

HttpError
Derive macro for HTTP error enums.