Description
Axum Responses is a crate designed to simplify the creation and handling of HTTP responses in applications built with Axum. It provides abstractions for handling standardized JSON responses, file responses, and error management, making it easier to build robust web applications.
Installation
Add the dependency to your Cargo.toml:
[]
= "0.5.0"
Features
-
Standarized JSON Responses: Easily create standardized JSON responses for common HTTP status codes like
200 OK,201 Created,400 Bad Request,404 Not Found, and more. -
Friendly File Response Creation: Use a builder pattern to create file responses and downloads with ease.
-
Error Handling: Define and manage HTTP errors with custom error types using the
HttpErrorderive macro and convert them directly into JSON responses. All of this being compatible withthiserror.
Usage
The JsonResponse Structure
This structure allows you to build responses with a status code, JSON body, and custom headers using a builder pattern.
use JsonResponse;
use Serialize;
async
Resulting Response
Examples
You can find complete examples in the examples directory.
Breaking Changes
-
From
HttpResponsetoJsonResponse: The main response structure has been renamed to better reflect its purpose of handling JSON responses. -
add_headerMethod: The method to add custom headers has been renamed fromadd_headertoheaderfor improved clarity.