Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RESTful APIs for Django projects/apps

What do you prefer when you want to "RESTify" your Django project in Django?

I came to the conclusion that there are really three options to do that:

  • django-piston http://bitbucket.org/jespern/django-piston/wiki/Home
  • django-rest-interface http://code.google.com/p/django-rest-interface/
  • django-restful-resources http://watchitlater.com/blog/2010/02/django-restful-resources/

Right way to do this for me would be to try all of'em and pick the one that is best for me, so meanwhile I'd like to hear yours...

Thanks.

like image 409
Ali Avatar asked Nov 20 '10 16:11

Ali


People also ask

Can Django be used for REST API?

Django REST framework is a powerful and flexible toolkit for building Web APIs. Some reasons you might want to use REST framework: The Web browsable API is a huge usability win for your developers.

Why do we use REST API in Django?

Main advantages of Django REST framework: Simplicity, flexibility, quality, and test coverage of source code. Powerful serialization engine compatible with both ORM and non-ORM data sources. Pluggable and easy to customise emitters, parsers, validators and authenticators.


2 Answers

I'm most familiar with django-piston, so I would naturally steer you in that direction.

A quick glance at the other two, though, indicates that django-rest-interface does nothing more than expose models as resources, and that django-restful-resources is some guy's one-off attempt at the same.

Piston, if I recall correctly, grew out of bitbucket.org's own site development, and allows a lot of flexibility - you can return almost any object from your resource's access methods, not just model instances, and it will be properly encoded. It also has built-in support for some nice features, like form validation (if you can get it to work right, anyway) and request throttling, among other things.

like image 151
eternicode Avatar answered Sep 18 '22 16:09

eternicode


With the new class-based generic views in django 1.3 it will be super-easy to implement your own rest interface, with custom serializers and deserializers, replicating the almost complete piston's implementation using just stock code. I made a View(1.3)-based rest module in 500 lines of code, with generic RESTful resource class and sub resources, natural key support for associations, json and XML serialization and more. the module is really tailored upon my app's requirements

I did it to overcome a couple of limitations in piston's code, like having a query set modified (e.g. With .values(...)) before the handler calling .get() on it, or not being able to use a model's method in serialization.

If you do it as you need it, in a couple of days you'll have a working set of classes and mixins, that you will fully understand and be in control of.

like image 32
rewritten Avatar answered Sep 19 '22 16:09

rewritten