5 ms·
Please stop RESTfully abusing HTTP
- rahulrav 12y agoThere is one good reason to do it. To support JSONP (json with padding). If you use JSONP and the server sends an HTTP response code which is not 2XX, then the browser does not allow JavaScript to parse the response body at all. There is a way to work around this, which is to use CORS. However, that is not supported in all browsers. So pick your poison.
- mcv 12y agoCORS is not a workaround; it's the right way to do it. JSONP is an ugly hack that should be avoided.
- mcv 12y agoThe title makes it sound like there's something wrong with using HTTP for REST, but the problem described in the article is that some people don't fully use HTTP for REST. It's totally possible to use status codes properly, but I do see a lot of projects where status codes aren't used (not just for AJAX, but even for regular pages; instead they redirect to the homepage on a 404, for example). The problem here is not using HTTP properly. HTTP suits this purpose perfectly, so ignoring HTTP is a bad idea.
- voidr 12y ago> This relegates HTTP to nothing more than a transport protocol. Well maybe because it is a transport protocol, it stands for: Hypertext Transfer Protocol HTTP is a way to send a message from point A to point B. If your API is tied to HTTP, then you'll have a hard time reusing the same code for another transport protocol, like websockets. Sometimes it makes a lot of sense to use HTTP headers codes for error handling, sometimes it just doesn't work, you can't shoehorn HTTP/REST into everything and expect something good to come out of it.