Skip to content Skip to sidebar Skip to footer

Jsonstub Response Not Showing

axios.get('http://jsonstub.com', { headers: { 'Content-Type': 'application/json', 'JsonStub-User-Key': '1699b7fc-cdcb-4205-b30a-b9b3626246c5', 'JsonStub-Project-Key':

Solution 1:

It's because the header 'Content-Type': 'application/json' is not sent in HTTP request.

In axios, if the request body is empty, Content-Type would be removed from HTTP headers. Anyway, Content-Type is the type of request body, so this design makes sense. Refer to discussion in GitHub.

However, Jsonstub announced that the Content-Type: application/json header must always be present for any stubbed requests. That's why you get strange html response when header 'Content-Type': 'application/json' is missing.

The workaround is simple, pass arbitrary data in HTTP request body:

axios.get('http://jsonstub.com', {
  headers: {
    'Content-Type': 'application/json',
    'JsonStub-User-Key': '1699b7fc-cdcb-4205-b30a-b9b3626246c5',
    'JsonStub-Project-Key': 'f39f1bd2-d303-4b7e-9a11-c0f049a46f87'
  },
  data: {}
}).then((data) => console.log(data))

Solution 2:

Maybe it's a CORS problem? Can you have a look at the DevTools Console output?

The content of the HTML response could also be helpful...

Post a Comment for "Jsonstub Response Not Showing"