Skip to content
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

Fix object spread on body #102

Merged
merged 1 commit into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ const Frisbee = require('frisbee');

* **Tip**: You'll most likely want to set the `"Accept"` header to `"application/json"` and the `"Content-Type"` header to `"application/json"`

* `body` (Object) - an object containing default body payload to send with every request (API method specific `params` options will override or extend properties defined here, but not deep merge)
* `body` (Object) - an object containing default body payload to send with every request (Provided body objects will shallow-merge with the defaults.)

* `params` (Object) - an object containing default querystring parameters to send with every request (API method specific `params` options will override or extend properties defined here, but will not deep merge)

Expand Down
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,11 @@ class Frisbee {
signal
};

if (this.opts.body || options.body)
opts.body = { ...this.opts.body, ...options.body };
if (this.opts.body || options.body) {
opts.body = typeof options.body === 'object'
? {...this.opts.body, ...options.body}
: (options.body ? options.body : this.opts.body);
}

if (this.opts.params || options.params)
opts.params = { ...this.opts.params, ...options.params };
Expand Down