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
Hello there. I realized that wretch loses the request body for the PUT, POST, and PATCH methods if the body type is FormData and you pass it directly to the .put(), .post(), or .patch() methods as their first argument.
A sample code to demo the problem:
constrequestBody=newFormData()requestBody.append("field1","data 1");requestBody.append("field2","data 2");wretch()// here the body is passed as the first argument, and the method does Jasonify it before attaching the data to the request..post(requestBody,"SERVER_URL")
To see the problem in action, please check this sandbox out, and click on the red button. As you see, the Content-Type value is wrong, and there is nothing in the parsedBody.
We know that the native fetch API supports FormData, and I think that, since wretch is supposed to be a wrapper around it, the .put(), .post(), and .patch() methods need to support FormData inputs.
Hello there. I realized that
wretch
loses the request body for the PUT, POST, and PATCH methods if the body type is FormData and you pass it directly to the .put(), .post(), or .patch() methods as their first argument.A sample code to demo the problem:
To see the problem in action, please check this sandbox out, and click on the red button. As you see, the
Content-Type
value is wrong, and there is nothing in theparsedBody
.We know that the native fetch API supports FormData, and I think that, since
wretch
is supposed to be a wrapper around it, the .put(), .post(), and .patch() methods need to support FormData inputs.To address the issue, we need to update this line to exclude FormData objects:
https://github.com/elbywan/wretch/blob/master/src/core.ts#L95
Maybe something like:
The text was updated successfully, but these errors were encountered: