| Crates.io | into-response |
| lib.rs | into-response |
| version | 0.3.1 |
| created_at | 2024-12-20 14:37:51.340722+00 |
| updated_at | 2025-03-21 16:34:17.870991+00 |
| description | IntoResponse derive for Axum framework. |
| homepage | https://github.com/NuclEnergy/into-response |
| repository | https://github.com/NuclEnergy/into-response |
| max_upload_size | |
| id | 1490226 |
| size | 26,934 |
IntoResponse is a Rust crate that provides utilities for deriving and implementing the IntoResponse trait for custom types. It offers a convenient way to convert your custom types into HTTP responses with minimal boilerplate.
IntoResponse trait#[into_response(status = ...)] attributeAdd into_response to your Cargo.toml:
[dependencies]
into_response = "0.3"
use into_response::IntoResponse;
#[derive(IntoResponse)]
struct MyResponse {
message: String,
}
fn main() {
let response = MyResponse {
message: "Hello, world!".to_string(),
};
// By default, the HTTP status is axum::http::StatusCode::OK.
let response = response.into_response();
assert_eq!(response.status(), axum::http::StatusCode::OK);
}
You can specify a custom HTTP status code using the #[into_response(status = ...)] attribute:
use into_response::IntoResponse;
#[derive(IntoResponse)]
#[into_response(status = 201)]
struct MyResponse {
message: String,
}
fn main() {
let response = MyResponse {
message: "Created successfully".to_string(),
};
let response = response.into_response();
// The HTTP status will be axum::http::StatusCode::CREATED.
assert_eq!(response.status(), axum::http::StatusCode::CREATED);
}
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request.
Special thanks to the Rust community for their contributions and support.