hippie icon indicating copy to clipboard operation
hippie copied to clipboard

API response reverts to string, despite setting as JSON

Open rob4629 opened this issue 4 years ago • 0 comments

Specifying the hippie request as JSON: hippie.json(), doesn't result in the response being JSON.

What I'm doing (example):

// Create User Example
const hippieCreateUserRequest = () => {
  const { body: { user }} = await hippie()
    .base(baseUrl)
    .auth(username, password)
    .json()
    .headers(headers)
    .post(route)
    .send(data)
    .expectStatus(201)
    .end();
}

I'm also logging out when I use the parser:

exports.json = function(data, fn) {
  var res = null;
  var err = null;

  if (data) {
    console.log("using JSON");
    try {
      res = JSON.parse(data);
      console.log(res);
    } catch (e) {
...

Which results in res being a JSON object. However, somewhere along the line, it's converted back to a string 🤷‍♂️.

My assumption here is, by specifying hippie.json(), the response should also be JSON.

rob4629 avatar Jul 20 '20 20:07 rob4629