I am curious how other developers reconcile http://www.w3.org/DesignIssues/Axioms.html#opaque in the context of web caching. I prefer the Rails' approach of suffixing resource requests based on the format I want, i.开发者_JS百科e. .json or .xml, rather than relying on the accepts header, despite the fact that it is not URI-opaque.
The same issue rears its head with XHR's. Without the addition of a query param to differentiate it from standard HTTP Requests, caching must be disabled.
I have personally opted that the purest interpretation of URI Opacity may be more academic than practical. Opinions?
The format of a URI has nothing to do with cacheability, other than noting that requests with query parameters are not cacheable by default. Everything about the cacheability of a GET request is driven by the Cache-Control, Expires, and Last-Modified (for heuristic caching) headers on the server response, and these don't have anything to do with whether the resource is dynamically or statically generated (or rather, your browser doesn't care and can't tell the difference).
URL opacity is meant to promote one of the primary principles of REST, which is that services should be hypermedia-driven, and that really, clients should only "know" a few well-known entry point URLs, and get everywhere else by navigating links and forms (or their API equivalents).
精彩评论