[Django]-Framework for Implementing REST web service in Django


NOTE: Since this post was written, django-piston is no longer
actively maintained. As others have mentioned, look into tastypie
or django-rest-framework.

Indeed, you can roll your own, but there’s a lot of boilerplate involved.

django-piston is an exceptionally easy to use, and extensible, micro-framework. In addition to mocking up all the necessary views and url patterns, it supports directly mapping models to a REST interface, which is nice if you have a simple use case. I’d suggest looking into it.


And since this question still rated pretty highly in my searches on Google, I’ll add this alternative to the mix: http://django-rest-framework.org/

My initial impression is that it does a very good job of embodying the RESTful API design principles described here: http://readthedocs.org/docs/restful-api-design/en/latest/


Using django-rest-interface

Still true.

It’s quite trivial to roll your own. Each REST URI maps to a view function. Each REST method (GET, POST, PUT, DELETE) is a simple condition in the view function.




One way is to roll your own, or use django-piston which is excellent. But the problem I have with piston is that is kind a made to be attached to a existing django-project to add an API. It is not so much made for building a resource oriented API with support for formats including HTML.

The way I see the use case for Piston is, you have a complete website that serves up html content, but then you would attach an api to that at the url /api/*. Then you go and add Piston to it. With this use case Piston is great, no rewrite needed for existing code and you get whatever you need. It may be that Piston works well without separating the api from the user facing part of the site, but I haven’t tried that.

It is easier to try to explain this with some examples:



Bitbucket is made with Django and django-piston for the API, while Github is made with Ruby On Rails wich has built in support for resources with different formats. I am not saying that you should switch to RoR, because we all love Django, and I am not saying that you couldn’t do this with django, but it would be tedious to do this yourself on every view.

So a co-worker and I decided that we wanted some of the “magic” of RoR in Django, but we didn’t want it to be magical, but make our lives easier without abstracting everything. So jgorset wrote Respite which is a little Django framework to make “RESTful” APIs in the same fashion as RoR does, but in Django. It is still in early development, but we use it daily in our work projects and it is highly customizable, much like Django itself. It tries to simplify making resource oriented webpages, and structure your code without getting in your way.

So naturally my recommendation would be to look at, and try Respite: https://github.com/jgorset/django-respite/


tastypie is also an option, I’ve just tried it and it seemed painless until now. I’m playing with a dummy app that exposes an API to a backbone.js client and I’ve hit no brick walls with this library. This article got me to try it.

Leave a comment