Introduction:
After reading a lot about HTTP and REST, you spent several hours developing a clever content negotiation scheme. So your web API can serve XML, JSON, and HTML from a single URL. Because, you know, a resource should have only one URL, and other views should be requested using headers Accept. You begin to wonder why it took 20 years for this implementation.
And that's when reality hits you in the face .
So, to help browsers (and try to debug themselves) with enforcing your service to serve the type of content you want, you do what every self-respecting evangelist from REST despises you for: File name extensions.
Despite the eternal torment in hell, is the use of Content-Location+ .extacceptable?
Say we have users /users/:loginname, for example /users/bob. That would be the API endpoint for anything that could set the right header Accept. But for any possible Content-Type(or at least some) we allow an alternative access method, and this is a URL with a file type suffix. For example, /users/bob.htmlto represent HTML. Suppose (and this is a big guess to make) the entry names will never contain a period / period.
Inquiry:
GET /users/bob.json HTTP/1.1
Host: example.com
Answer:
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 14
Content-Location: /users/bob
{"foo": "bar"}
( ) .
, <a href="/users/bob.html">Bob</a>.
vCard ( /Outlook/) <a href="/users/bob.vcf">Bob</a>.
- , ? ?
: , . , , , ...