Skip to content

A Rust macro for easily generating HTTP responses from enums in Axum applications.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

lillianrubyrose/axum-enum-response

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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}
}

About

A Rust macro for easily generating HTTP responses from enums in Axum applications.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages