-
-
Notifications
You must be signed in to change notification settings - Fork 409
Description
Hello team! Thanks for sharing this great library. We're currently trying it for our development process.
Context
To perform API requests, we can make use of the Content-Type
header to tell the API the media type of the payload.
When the payload complies with the FormData format, multipart/form-data
should be the value of this header. According to the documentation, a boundary is required. Otherwise, the API won't work as expected:
Content-Type: multipart/form-data; boundary=something
So if that's the case, it's better to leave the Content-Type
header empty.
Current scenario
The generator creates a HttpClient
class with the following baseApiParams
attribute similar like this example:
private baseApiParams: RequestParams = {
credentials: "same-origin",
headers: {
"Content-Type": "application/json",
},
redirect: "follow",
referrerPolicy: "no-referrer",
};
I can override the header when invoking the client's method if my endpoint accepts multipart/form-data
:
await slotClient.patchEspApi(slot.id, values, {
headers: {
Authorization: loginInfo.token,
"Content-Type": "multipart/form-data"
},
});
I don't have the boundary
information which can lead to the issue described in the previous section.
If I remove the header, the request is sent with application/json
type which is unwanted.
In any case, I can't remove the header in the final request causing the API don't understand the form data.
Proposed solution
My hot-fix is to remove the hardcoded value of "Content-Type": "application/json",
from the generated HttpClient
class.
I'm not sure if I can use it in a way that removes completely the header. But I think you can update the generator tool to not hardcode that header in the HttpClient
class.
Let me know your thoughts.