You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have looked for existing issues (including closed) about this
Feature Request
This is not something super important, but I want to describe a potential semantic improvement on how axum uses HTTP.
Axum currently returns HTTP status 200 for a route that returns the unit type:
async fn my_route() -> () { // explicit return type for clarity
println!("I am not returning anything");
}
But a HTTP 204 status code (=no content) would be more precise, because the unit type is essentially an empty value.
Motivation
This is mostly useful for routes that get called via ajax. By being more explicit, API breakage can be detected more easily and ajax handling logic may branch on the status code.
Somewhat related: Option<T> return types could also benefit from a 200/204 distinction.
Proposal
My understanding is that this part has to be changed:
We cannot change the behavior of `<() as IntoResponse>::into_response`,
so add a newtype struct to explicitly use 204 No Content status.
Refs: tokio-rs#2363, tokio-rs#2393
We cannot change the behavior of `<() as IntoResponse>::into_response`,
so add a newtype struct to explicitly use 204 No Content status.
Refs: tokio-rs#2363, tokio-rs#2393
Feature Request
This is not something super important, but I want to describe a potential semantic improvement on how axum uses HTTP.
Axum currently returns HTTP status 200 for a route that returns the unit type:
But a HTTP 204 status code (=no content) would be more precise, because the unit type is essentially an empty value.
Motivation
This is mostly useful for routes that get called via ajax. By being more explicit, API breakage can be detected more easily and ajax handling logic may branch on the status code.
Somewhat related:
Option<T>
return types could also benefit from a 200/204 distinction.Proposal
My understanding is that this part has to be changed:
axum/axum-core/src/response/into_response.rs
Lines 125 to 129 in 2e963ce
This could be as simple as creating the response like above, but before returning, update the status code to 204.
Alternatives
Just leave things as they are. Which would still be fine.
The text was updated successfully, but these errors were encountered: