Beginner
Beginner

Reputation: 202

REST Client extension - API response as HTML

I wanted to use vs code's extension REST client for testing purposes. So I used a curl of an existing API running on my local machine. But instead of JSON, I got HTML as a response. The curl works as expected in the terminal but not with the extension. The same Behaviour is with another extension named Thunder Client.

Postman is getting JSON responses for the same API I believe that issue lies within vs code itself, I just don't know how to resolve it.

Upvotes: 0

Views: 1105

Answers (1)

Mark Chassy
Mark Chassy

Reputation: 159

According to this article: https://softwareengineering.stackexchange.com/questions/207835/is-it-ok-to-return-html-from-a-json-api If you have declared you only accept one format in the header then the service should only send back that format or throw an error. If you have not put an ACCEPT in the header, the the service may send back whatever. Check what is in the ACCEPT header:

enter image description here

But also check how Thunder Client translates the call in powershell: enter image description here

I see that in my call the response is translated to JSON. I would guess that most REST clients are assuming that users want to work in JSON. Maybe that's what your two REST clients are doing?

Upvotes: 1

Related Questions