DioxusLabs / DioxusLabs/dioxus

Implement FromResponse on StatusCode

Open
#5,297 0 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
39.1k
Forks
1.9k
Avg merge
4d 10h
Merged PRs (30d)
4

Description

## Feature Request
I would like to return custom http status in server function.

In axum, this can be as easy as returning [`http::status::StatusCode`](https://docs.rs/http/latest/http/status/struct.StatusCode.html), but since dioxus requires return types to implement the [`FromResponse` trait](https://docs.rs/dioxus/latest/dioxus/prelude/dioxus_fullstack/trait.FromResponse.html) in addition to [`IntoResponse`](https://docs.rs/axum/latest/axum/response/trait.IntoResponse.html), and we can't define a foreign trait on a foreign struct, we need to write a wrapper for `StatusCode` and remap every status code. It would be easier if dioxus implements [`FromResponse` trait](https://docs.rs/dioxus/latest/dioxus/prelude/dioxus_fullstack/trait.FromResponse.html) for `StatusCode` so we can use `StatusCode` directly in the response type.

For example:
```rs
#[server]
pub async fn my_endpoint() -> Result {
Ok(StatusCode::NO_CONTENT)
}
```

## Implement Suggestion
I'm guessing we just need to implement the [`FromResponse` trait](https://docs.rs/dioxus/latest/dioxus/prelude/dioxus_fullstack/trait.FromResponse.html) for [`http::status::StatusCode`](https://docs.rs/http/latest/http/status/struct.StatusCode.html)?

Or perhaps there's already an easy way to return custom http status that I'm not aware of? (I tried to search through github issues and on discord but all I could find were custom http status on error, not on success).

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.