4 ms·
If you are designing a REST API, please don't follow this author's advice and return HTML instead of JSON. HTML takes much longer to parse and makes the API mor
by eterevsky 4y ago
If you are designing a REST API, please don't follow this author's advice and return HTML instead of JSON. HTML takes much longer to parse and makes the API more fragile.
The history did its job: it preserved the most useful features of the original idea (expressing RPCs as URLs in GET and POST requests) and has dropped the unnecessarily complicated bits.
What this article is about is a pedantic terminology battle of whether to call the current practice REST or not.
- irrational 4y agoDon’t parse the HTML, just display it. That’s what the browser does best.
- woojoo666 4y agoNot the parent commenter, but I believe the idea is that if the webpage uses a framework like React or Angular, then the server doesn't need to send html, it can just send the bare minimum data necessary (in JSON) and the client turns it into html and displays it. In other words, HTML is just the standard format that the browser uses. But if you use frameworks or define your own application specific formats, you can send less information over the wire and have it properly decoded and displayed by your client-side javascript.
- woodweb 4y agoWhat if a mobile application wants to use the API?
- NoGravitas 4y agoREST systems are designed for use with "generic" clients. The generic client for REST systems on the WWW is a browser. There is probably one available for your mobile platform.
- firstbabylonian 4y agoWhat if a native application (mobile or desktop) wants to consume the API?
- chasinglogic 4y agoThis to me is the real question. I don't see how you could easily create multiple clients if you're practicing what is preached in the article. You're really tying your server to the browser at that point so things like CLI clients and mobile clients become painful to write (not impossible but ain't nobody got time for parsing HTML when browsers do a perfectly good job of it, not to mention CSS.).
- z9znz 4y agoThis article really is about getting people to use their overloaded HTML libraries.
- krainboltgreene 4y ago> If you are designing a REST API, please don't follow this author's advice and return HTML instead of JSON. HTML takes much longer to parse and makes the API more fragile. you're describing what a browser does. > has dropped the unnecessarily complicated bits. you're viewing this content from a browser.
- eterevsky 4y agoWhat's your point? If something works for the purposes of UI, it doesn't mean it is good for an API.