Replies: 1 comment 3 replies
-
Request objects are immutable and while they don't have a Ky allows you to return a new request from a import snakecaseKeys from 'snakecase-keys';
import ky from 'ky';
const api = ky.extend({
hooks : {
beforeRequest : [
async (request, options) => {
const json = await request.json();
const snaked = snakecaseKeys(json);
return new Request(request.url, {
...options,
body : snaked
});
}
]
}
}); You could further improve this hook by having it short circuit if the |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm looking to automatically transform from camel case to snake case all objects I'm sending in a POST request. Thought about using the
beforeRequest
hook. But can't figure out how to modify the body or the json object. TheRequest
object doesn't seem to have abody
property set.Beta Was this translation helpful? Give feedback.
All reactions