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

POST/PUT requests are not properly sending json body #222

Closed
meash-nrel opened this Issue Oct 10, 2018 · 6 comments

Comments

Projects
None yet
3 participants
@meash-nrel
Copy link

meash-nrel commented Oct 10, 2018

My code worked in 3.1.1 and earlier, but after updating to 3.2.0 latest, all POST and PUT requests in my application are broken.

The request payload is coming across as "[object Object]" instead of the expected json stringified object. Request header is getting this set to "Content-Type: text/plain;charset=UTF-8", expected it to auto-set it to "application/json" as it did before.

Reverted API (and ORM and Authentication dependencies) to 3.1.1, and those same calls are coming back with the json string in body and 'application/json' as expected.

@meash-nrel

This comment has been minimized.

Copy link
Author

meash-nrel commented Oct 10, 2018

Defaults mentioned in docs aren't being applied. If I set those default values in api initial configuration, it corrects this issue.
.withDefaults({headers: {'Content-Type':'application/json', 'Accept':'application/json'}})

I output this.defaults in the request() function in aurelia-api.js and it was an empty object. Not sure how but this.defaults is going from being set in constructor to being empty object by the time I hit request().

@RWOverdijk

This comment has been minimized.

Copy link
Member

RWOverdijk commented Oct 11, 2018

@meash-nrel That's unfortunate, I'm sorry you're having trouble with this.

Having figured out the issue, do you feel confident submitting a PR?

@carusology

This comment has been minimized.

Copy link
Contributor

carusology commented Nov 6, 2018

Caused by #215. @netcitylife accurately identified the issue, but was ignored :(

30dbbc5#diff-9d9a6cd82f41984872a66a3ab0d440c4R74

On the linked line, the newClient.defaults property is the empty object when it is unconfigured - not null. Then it goes on and overrides the aurelia-api defaults with the empty object.

Workaround is to set the defaults to a falsey value in the config.registerEndpoint() function:

plugin(
    'aurelia-api',
    config => {
      config.registerEndpoint(
          'github',
          endpoint => endpoint.withDefaults(undefined)
      )
    }
);
@RWOverdijk

This comment has been minimized.

Copy link
Member

RWOverdijk commented Nov 6, 2018

@carusology Nice find. Maybe you want to contribute a more sustainable fix? It'd be much appreciated!

@carusology

This comment has been minimized.

Copy link
Contributor

carusology commented Nov 6, 2018

@RWOverdijk
Is there documentation on how to run the tests anywhere?

npm install and npm test do not appear to be sufficient. The contributing guidelines reference running gulp globally, but that is what npm test is doing.

@RWOverdijk

This comment has been minimized.

Copy link
Member

RWOverdijk commented Nov 7, 2018

@carusology I'm pretty sure that just running yarn test (or npm) should just work if you run jspm install first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment