nuxt-open-fetch
nuxt-open-fetch copied to clipboard
Support `multipart/formdata` (and other Content-Types)
The problem
One thing missing right now is support for non-json content types, especially multipart/formdata, which is usually used for file upload, as far as I know.
While it is possible to set a FormData object as the body, which will automatically set the right header, there is no type safety for this. Furthermore you even get a TypeScript error, because the nuxt-open-fetch client expects the bodies as normal object. (See #70)
Potential solution
The openapi-fetch library handles this via a bodySerializer option. This would be a huge improvement for nuxt-open-fetch.
There are two potential improvements that could be made on a TypeScript level for this option:
- Make the option mandatory, when a Content-Type other then
application/jsonis required for the request - Make the expected return type
FormDataorURLSearchParamswhen the Content-Type is set tomultipart/formdataorapplication/x-www-form-urlencodedrespectively.
Alternative
I was also thinking about something like a formData (and urlEncodedData) property, that could be used instead of the body and would automatically do the serializing under the hood when set. These could also be enforced via TypeScript. These options would have a nicer DX, but are less flexible and probably a bit more involved.
Additional information
- [x] Would you be willing to help implement this feature?
Final checks
- [x] Read the contribution guide.
- [x] Check existing discussions and issues.