-
|
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 |
Beta Was this translation helpful? Give feedback.
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.
Request objects are immutable and while they don't have a
bodyproperty, they do have various methods for reading the body.Ky allows you to return a new request from a
beforeRequesthook. So something like this should work...You could further improve…