Expand description
§axum_responses
Ergonomic response builders for Axum web applications.
This crate provides three main response types that implement IntoResponse:
JsonResponse- Standardized JSON API responsesFile- File downloads and inline contentRedirect- HTTP redirects
§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§
Macros§
- response
- Creates a JSON response with the specified status code and optional data.
Structs§
- File
- A builder for creating file download/inline responses.
- Json
Response - A builder for creating standardized JSON HTTP responses.
- Json
Response Body - Represents the JSON body structure of a response. Useful for testing and deserialization.
- Redirect
- A builder for creating HTTP redirect responses.
Enums§
- Content
Disposition - Specifies how the content should be presented to the user.
Derive Macros§
- Http
Error - Derive macro for HTTP error enums.