Should I use the Content-Location header this way?

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>.

- , ? ?

: , . , , , ...

+5
2

, Content-Location ; URI.

+1

RFC 2616:

The Content-Location entity-header field MAY be used to supply 
the resource location for the entity enclosed in the message 
when that entity is accessible from a location separate from 
the requested resource URI.

The Content-Location value is not a replacement for the original
requested URI; it is only a statement of the location of the resource 
corresponding to this particular entity at the time of the request. 

, , Content-Location . , URL-, . /users/bob,/users/bob.vfc,/users/bob.html - .

0

All Articles