-
-
Notifications
You must be signed in to change notification settings - Fork 942
New issue
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
beforeRequest
doesn't merge options.json
#1408
Comments
Because it's converted into |
Is there ways to merge with |
Try this: const client = got.extend({
prefixUrl: 'https://domain.com',
hooks: {
beforeRequest: [
options => {
if (options.method === 'post' || options.method === 'POST') {
options.json = options.json ?? {};
options.json.myValue = 'newValue';
options.body = JSON.stringify(options.json);
}
},
],
},
}); |
I think you should use the |
I cant' use the |
I think we can pass a |
Same problem here, also some explanations: |
Ah... I just forgot that:
So you'd have to const client = got.extend({
prefixUrl: 'https://domain.com',
hooks: {
beforeRequest: [
options => {
if (options.method === 'post' || options.method === 'POST') {
options.json = JSON.parse(options.body);
options.json.myValue = 'newValue';
options.body = JSON.stringify(options.json);
}
},
],
},
});
In the upcoming release this will be possible. The Yet another solution is to use the Another way is to pass the body in the |
Hi,
I have custom
options.json
inbeforeRequest
hook, but it not working well.Describe the bug
Actual behavior
In fact,
myValue
doesn't merge with options.json data.Checklist
The text was updated successfully, but these errors were encountered: