sideshowcoder / canned

Server to respond with fake API responses, by using a directory of files for finding out what to say!
213 stars 46 forks source link

Json not appearing in browser #92

Closed normand1 closed 8 years ago

normand1 commented 8 years ago

I have a simple file with a single Json object.

filename: index.get.json

    //! statusCode: 200
    { "content": "I am a wildcard comment for any id", "author": "sideshowcoder" }

After starting canned I open my browser and type http://localhost:3000/test into the address bar. I see no output in chrome, safari, or firefox, and I get this response from canned:

  request: get /test not found

Chrome shows this error in the developer tools console:

  Failed to load resource: the server responded with a status of 404 (Not Found)

From the terminal I type:

   $ curl http://localhost:3000/test

and get this response:

   {"content":"I am a wildcard comment for any id","author":"sideshowcoder"}

and this output from canned:

  request: get /test served via: ./index.get.json
git-jiby-me commented 8 years ago

@normand1 this is because, canned reads the request accept header to decide which file to respond with.

If the accept headers says i am expecting html, then canned will return .get.html and if accept headers says 'i am expecting json' then canned will return .get.json.

When you just enter http://localhost:3000/test in browser, browser is asking for give me html content for this url, rather than give me json content for this url.

If you want to debug the API, then use something like postman

sideshowcoder commented 8 years ago

For reference if you want to do the curl request try:

$ curl -H'Accept: application/json' http://localhost:3000/test