Add a native way to create and respond to requests with multipart forms #2624
Labels
A-axum-extra
C-feature-request
Category: A feature request, i.e: not implemented / a PR.
E-medium
Call for participation: Experience needed to fix: Medium / intermediate
Feature Request
Motivation
Currently, as far as I can tell, Axum does not provide a native way to respond to requests with multipart forms.
An endpoint might return a multipart form for a variety of reasons, but the most common being the need to include multiple pieces of data (a json, a file, plaintext) in a single request.
For example, I would like to send a json and a file in a single response.
Proposal
I am not comfortable with the Axum codebase, so I am unsure of the most idiomatic ways do this, but there are a few options that may work:
Implement
IntoResponse
for theMultipart
extractor, and add methods likeadd_field()
to the existing impls for multipart.It may also make more sense to create a separate MultipartBuilder and implement
IntoResponse
for that type, and add builder methods, Reqwest's implementation could be used as a reference.I don't think there are any significant drawbacks, it will marginally increase the complexity of exposed formdata APIs, but I believe the benefits outweigh the drawbacks.
Alternatives
As far as I can tell, alternatives involve:
reqwest
's implementation and manually interopI am willing to attempt to implement this, however I am not confident in my abilities to do so.
The text was updated successfully, but these errors were encountered: