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

Cannot post a body that is not an object #52

Open
j7m4 opened this issue Jun 26, 2013 · 3 comments
Open

Cannot post a body that is not an object #52

j7m4 opened this issue Jun 26, 2013 · 3 comments

Comments

@j7m4
Copy link

j7m4 commented Jun 26, 2013

I'm testing an existing XML-based rest API. The XML string is not sent with:
.post("/my/uri", "xml")

I looked into api-easy.js, and I think I see the issue. The _request function expects data to be an object. Fixing this would not be as simple allowing the body to be either an object or string -- as this could possibly conflict with the uri parameter.

One possible solution is to have the body continue to be an object, but for unkown mime types, encapsulate the data in an object, like such: {"body": "xml"}.

@joehler
Copy link

joehler commented Jun 26, 2013

Take a look at this fork. I had to make some modifications to allow for XML testing and this might work for you.

https://github.com/oncron/api-easy/

@j7m4
Copy link
Author

j7m4 commented Jun 26, 2013

I think your fork would work, but I believe there may be a subtle bug. If no URI is passed in and the data is passed in as a string, then the uri variable would be assigned the data.

I think as long as you pass in the uri explicitly, your fix would work.

@philipp-classen
Copy link

One hack is to wrap your xml string in a Buffer (new Buffer(xmlString)). From the perspective of api-easy, it behaves like a string but it is an object, so the string logic is not triggered.

You can wrap it as a function, so it looks less ugly.
function xmlBody (xmlString) { return new Buffer(xmlString); }

However, it still does not feel right. I think api-easy is not really intended to be used with XML but only with JSON.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants