Should a REST API return HTML?

Should a REST API return HTML?

One of the core benefits of REST is its separation of representation (encoding) from the underlying resource being accessed. It’s perfectly fine to return HTML if the client requests it as a preference via the Accept header.

Can API return HTML?

Returning html content from Web API can be very useful, when you want to provide content that can be embedded into html page easily.

Is JSON an HTML?

JavaScript Object Notation (JSON) is a standard text-based format for representing structured data based on JavaScript object syntax. Basic computer literacy, a basic understanding of HTML and CSS, familiarity with JavaScript basics (see First steps and Building blocks) and OOJS basics (see Introduction to objects).

What’s the problem with JSON as an endpoint?

JSON doesn’t have this problem, because it’s just data, not web page structure. The main problem is that it tightly couples the server to the client, who must know the HTML structure. It also makes the endpoints more difficult to re-use in new ways or new applications.

What do I need to change in my front-end code for the API to return JSON?

What do I need to change in my front-end code for the API to return JSON. Header is not correct. Valid header for JSON response: Also double check you have selected the correct HTTP method in the dropdown box next to the input bar on postman. Thanks for contributing an answer to Stack Overflow!

What is actually wrong with an endpoint returning HTML rather?

I’m gonna tell you this: an endpoint that returns HTML reduces your dependency on JavaScript libraries and reduces the load on the user’s browser since it won’t need to interpret/execute JS code to create DOM objects – the HTML is already there, it’s just a matter of parsing the elements and rendering them.

When do you use JSON instead of HTML?

If you are populating a web page with data, use JSON. If you are building up a web page from portions of web pages, use HTML. They may kinda sound like they’re the same thing, but they aren’t, at all. For one thing, when you are building up a portion of a web page using HTML returned by the server, you are working server-side.