-
Notifications
You must be signed in to change notification settings - Fork 66
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
Auto JSON.stringify for POST Requests #219
Conversation
Thanks @darseen so much for the PR! We will review it shortly! |
Hello @darseen, I reviewed your code, thanks again for the PR! What worries me is the fact that these changes will break the code of existing users of the library who will install the latest version. Do you think we could add a check inside the POST to determine if the body is already a string or not and then handle the conversion accordingly? What are your thoughts on that? |
Hi @tsolakoua, Thank you for taking the time to review the PR! You are absolutely correct, the current implementation would break backwards compatibility. Your suggestion for checking the type of the params before passing them to the client seems great to handle this issue. It could be as simple as: const stringifiedParams = typeof params === "string" ? params : JSON.stringify(params); and then pass the stringifiedParams to the client. Would you like me to implement the currently suggested approach? If so, should the README be changed in this case? |
Thanks for your quick response @darseen. If you want and you have time, feel free to go ahead and make the changes. Otherwise we will create a new PR whenever we have some time after we merge yours to master. Let me know what works the best for you. If we agree on merging this PR, I would just ask you to solve the conflicts. Maybe for the README we could keep it as it is in any case, to encourage the new users to use the method you've implemented. Thanks again for the PR, we really appreciate it :) |
Quality Gate passedIssues Measures |
Hi @tsolakoua, I have added the following changes: Changes
As for the current implementation of the stringifying of the params, I decided to add the check in the Tests
SuggestionsCurrently the codebase can be improved in many ways, since many parts of it is still using ES5 syntax. Here are some recommendations
From this:// request.js
body() {
if (this.verb !== 'POST') { return ''; }
else {
if (!this.bearerToken) {
return qs.stringify(this.params);
}
return this.params;
}
} To this:// request.js
body() {
if (this.verb !== 'POST') return '';
else if (!this.bearerToken) return qs.stringify(this.params);
return this.params;
} I would be glad to make such changes if you would like to implement these suggestions! |
The PR is merged, thanks so much @darseen! We checked your suggestions to improve the codebase and definitely are valid! |
Description
This PR fixes #202 where users were required to manually convert their data to a string using
JSON.stringify
for some POST requests. With this fix, data will now be automatically stringified before being sent in POST requests.I discovered this issue when I was rewriting the codebase in TypeScript for the unofficial package amadeus-ts, and decided to fix it for the official package as well.
Changes Made
JSON.stringify
to objects in POST requests.Testing