Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Html, Css, JavaScript, and Wasm response types #1921

Merged
merged 2 commits into from
Apr 17, 2023

Conversation

davidpdrsn
Copy link
Member

I think using T: IntoResponse is more flexible than the previous bound. For example you can response with the contents of a file with

Router::new().route(
    "/",
    get(|| async {
        let Ok(file) = tokio::fs::File::open("index.html").await else {
            return Err(StatusCode::INTERNAL_SERVER_ERROR);
        };
        Ok(Html(AsyncReadBody::new(file)))
    }),
);

Also added css, javascript, and wasm, because why not.

We can move Html into axum in 0.7.

Supersedes #1920

@davidpdrsn davidpdrsn requested a review from jplatte April 9, 2023 11:04
@davidpdrsn davidpdrsn enabled auto-merge (squash) April 9, 2023 11:04
@LiamGallagher737
Copy link

I just made a crate with a bunch of content types, maybe I could add them here. Most of them are too specific to have here but most of the image ones and files like pdf would be nice to have.
https://github.com/LiamGallagher737/more_axum_responses/blob/main/src/lib.rs

@davidpdrsn
Copy link
Member Author

but most of the image ones and files like pdf would be nice to have

As long they're just wrappers around plain data and don't require other dependencies I'm fine with it. But yeah some of those are quite specialized and probably not worth having.

Can you make a follow up pr when this is merged?

@davidpdrsn davidpdrsn merged commit e97462d into main Apr 17, 2023
@davidpdrsn davidpdrsn deleted the david/more-response-types branch April 17, 2023 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants