axum-enum-response

Crates.ioaxum-enum-response
lib.rsaxum-enum-response
version0.2.0
sourcesrc
created_at2024-02-28 19:12:27.571755
updated_at2024-08-26 09:13:32.39495
descriptionEasily create axum::http::Response's from Enums!
homepage
repositoryhttps://github.com/lillianrubyrose/axum-enum-response
max_upload_size
id1156858
size25,599
Lillian Rose (lillianrubyrose)

documentation

https://docs.rs/axum-enum-response

README

axum-enum-response

MSRV: 1.65.0

Easily create axum::http::Response's from Enums!

Example Usage

#[derive(serde::Serialize)]
struct SomeData {
	meow: String,
}

enum ErrorResponse {
   #[status_code(UNAUTHORIZED)]
   Unauthorized, // 401, empty body
   #[status_code(OK)]
   #[body("hello"=>"world")]
   Ok, // 200, body = {"hello": "world"}
   #[status_code(FORBIDDEN)]
   #[body("mew")]
   Forbidden, // 403, body = {"error": "mew"}
   #[status_code(INTERNAL_SERVER_ERROR)]
   FromUtf8Error(#[from] FromUtf8Error), // 500, body = {"error": FromUtf8Error::to_string()}
   #[status_code(INTERNAL_SERVER_ERROR)]
   InternalServerError(#[key("awwa")] String), // 500, body = {"awwa": STRING}
}
Commit count: 0

cargo fmt