Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

For those who haven't seen it, the awesome django-rest-framework has built in support for browsable, self-documenting, HATEOS APIs.

Here's a browsable example API: http://rest.ep.io/

Because your browser provides Accept: text/html by default you get back a nice html page describing the result for the API root. If you send Accept: text/json (click "json" at the bottom) you get back a json response.

You can follow the links in the html response to get to other parts of the API. You can also click "OPTIONS" to send an OPTION request to get a description of what you can send to that endpoint.

http://django-rest-framework.org/



How well does django-rest-framework do with nested (foreignkey) resources? I recently chose Tastypie for a project for that reason alone, but never ran across django-rest-framework to have considered it.

Looking at the django-rest-framework API examples, that's one thing I don't see, but is (at least for me) fairly critical.


It handles them fully. I haven't played with the many to many support, but from having looked through the code it fully supports getting/setting many to many relationships.

One thing that does seem to be a bit lacking is the documentation. I've used all three django frameworks though (piston, tastypie and django-rest-framework) and django-rest-framework wins in my book.


Can you get any of those three frameworks to expose arbitrary views? One of my biggest complaints with all of them is that they seem to only expose objects.


When you say objects I assume you mean model objects? In that case yes. I haven't used Piston or Tastypie in awhile, but I know that you can easily write views in django-rest-framework that aren't tied to models.

This is a bullet from the django-rest-framework page I linked above: "Modular architecture - MixIn classes can be used without requiring the Resource or ModelResource classes."

Here's one of the examples from django-rest-framework that is not tied to models: http://django-rest-framework.readthedocs.org/en/latest/examp...

And also, from the Tastypie docs: http://django-tastypie.readthedocs.org/en/latest/resources.h...


I read through both of those links and I think I wasn't clear with my initial question.

I want to expose arbitrary view methods to GET calls, not linked to any model, and not have to write a new class for every view I want to expose. Basically I want views to return the correct filetype (json, html, xml, etc) when requested. This is basically making django a little more rails-like. I'm leaning towards django-dynamicresponse currently.

I really like how the three you mentioned tie into Django's forms though, and that's quite a feature to give up.


Yes, you can get djangorestframework to be used without being tied to any model, or even without tying it to a resource. In its current incarnation, djangorestframework just follows the principle from generic class-based views.

You just define a view that inherits from djangorestframework.views.View, and implement the action methods (get/post/put/delete) that you want. These methods must return a dictionary, and the framework handles the part of dispatch and render the view in the proper format.


That was a really helpful answer, thanks! I'll be taking another look at djangorestframework; hopefully I didn't miss anything else.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: