Framework for Implementing REST web service in Django

17,412

Solution 1

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.

Solution 2

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/

Solution 3

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.

Done.

Solution 4

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

Github

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/

Solution 5

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.

Share:
17,412

Related videos on Youtube

Laizer
Author by

Laizer

US native. Israel-based software development. Currently working with Sefaria, open-sourcing Jewish texts. Besides software dev, interests in: Design Complexity Cities Sustainable Tech Lev on LinkedIn

Updated on August 18, 2020

Comments

  • Laizer
    Laizer over 3 years

    I'm looking to implement a RESTful interface for a Django application. It is primarily a data-service application - the interface will be (at this point) read-only.

    The question is which Django toolsets / frameworks make the most sense for this task.

    I see Django-rest and Django-piston. There's also the option of rolling my own.

    The question was asked here, but a good two years back. I'd like to know what the current state of play is.

    In this question, circa 2008, the strong majority vote was to not use any framework at all - just create Django views that reply with e.g. JSON. (The question was also addressed, crica 2008, here.)

    In the current landscape, what makes the most sense?

  • ncoghlan
    ncoghlan over 12 years
    I've since used this framework to implement a data model browser for my web application, and I've been very happy with it. It has a few quirks that you need to accommodate (e.g. the currently released version doesn't like fields that conflict with dict and list attributes, although the next release should fix that)
  • B Robster
    B Robster almost 12 years
    Update: Piston is not being actively maintained. Try tastypie or django-rest-framework. pydanny.com/choosing-an-api-framework-for-django.html
  • michel.iamit
    michel.iamit over 11 years
    Especially the browesable interface is saving a lot of time while developing! Many other advantages, so everyone starting rest implementation should have a look. I started with tastypie, but switched completely to django-rest-framework

Related