toastdriven/django-tastypie — pull request #394 by philipn (2012-03-03 04:07:40+00:00)
Title: Accept header based Api routing

This branch implements Accept: header based Api routing. This allows people to drop the /v1/, /v2/ from URLs. Just send a request with an (optional!) Accept: vnd.api.v1+json and you'll get back the Api(api_name='v1') instance. This is accomplished by register()'ing Api instances with an AcceptHeaderRouter object. All the existing URL-based api routing stuff is still there and is the default behavior.

Reading around, this is the approach that many REST nuts recommend. I've got no opinion as to whether or not this should be tastypie's default behavior, though.

There is full test coverage and docs. I placed the docs into the cookbook, but only because I wasn't sure where else to put them :)

There's some trickiness here, stemming from tastypie's internals being deeply coupled with URL routing. I did my best to mitigate this. My work here could probably be adapted to other stuff, like querystring-based Api routing (not sure if people really recommend / do that, though).