We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I wanted to snake case my FormData beforeRequest. The ky-hooks-change-case library only works with non-FormData. So, I wrote my own.
export const snakeCaseBody = (original) => { if (original instanceof FormData) { const body = new FormData(); [...original.keys()].forEach((key) => { body.set(snakeCase(key), original.get(key)!); }); return body; } return JSON.stringify(toSnakeCase(JSON.parse(original))); }; export const requestToSnakeCase = async (request, options) => { if (options.body) { const body = snakeCaseBody(options.body); return new Request(request, {body}); } };
I've got a unit test that proves snakeCaseBody works. I also logged the Content-Type header of the request and it looks correct:
snakeCaseBody
Content-Type multipart/form-data; boundary=----formdata-undici-066001922265
But on the receiving end of the API, I get an error that the body cannot be parsed as FormData.
Is this a limitation in ky, or am I doing something wrong?
The text was updated successfully, but these errors were encountered:
As long as the boundary is correct, I would expect it to work. We've had problems with that before.
boundary
Sorry, something went wrong.
Ok thanks. I’ll keep experimenting and see if I can figure it out.
No branches or pull requests
I wanted to snake case my FormData beforeRequest. The ky-hooks-change-case library only works with non-FormData. So, I wrote my own.
I've got a unit test that proves
snakeCaseBody
works. I also logged the Content-Type header of the request and it looks correct:But on the receiving end of the API, I get an error that the body cannot be parsed as FormData.
Is this a limitation in ky, or am I doing something wrong?
The text was updated successfully, but these errors were encountered: