[Django]-Django and Restful APIs

18๐Ÿ‘

โœ…

I believe the recently released django-piston is now the best solution for creating a proper REST interface in Django. django-piston

Note: django-piston seems to no longer be maintained (see comments below)

๐Ÿ‘คgsiegman

41๐Ÿ‘

For Django, besides tastypie and piston, django-rest-framework is a promising one worth mentioning. Iโ€™ve already migrated one of my projects on it smoothly.

Django REST framework is a lightweight REST framework for Django, that
aims to make it easy to build well-connected, self-describing RESTful
Web APIs.

Quick example:

from django.conf.urls.defaults import patterns, url
from djangorestframework.resources import ModelResource
from djangorestframework.views import ListOrCreateModelView, InstanceModelView
from myapp.models import MyModel

class MyResource(ModelResource):
    model = MyModel

urlpatterns = patterns('',
    url(r'^$', ListOrCreateModelView.as_view(resource=MyResource)),
    url(r'^(?P<pk>[^/]+)/$', InstanceModelView.as_view(resource=MyResource)),
)

Take the example from the official site, all above codes provide api, self explained documentation (like soap based webservice) and even sandboxing for testing. Very convenient.

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

๐Ÿ‘คSun Liwen

9๐Ÿ‘

django-tastypie is a good way to do it, their slogan: โ€œCreating delicious APIs for Django apps since 2010โ€ is pretty comforting ๐Ÿ˜‰

๐Ÿ‘คguerrerocarlos

5๐Ÿ‘

You could take look at django-dynamicresponse, which is a lightweight framework for adding REST API with JSON to your Django applications.

It requires minimal changes to add API support to existing Django apps, and makes it straight-forward to build-in API from the start in new projects.

Basically, it includes middleware support for parsing JSON into request.POST, in addition to serializing the returned context to JSON or rendering a template/redirecting conditionally based on the request type.

This approach differs from other frameworks (such as django-piston) in that you do not need to create separate handlers for API requests. You can also reuse your existing view logic, and keep using form validation etc. like normal views.

๐Ÿ‘คchrismi

4๐Ÿ‘

I donโ€™t know if this project can be useful for you, but sending a link can hardly hurt. Take a look at django-apibuilder , available from http://opensource.washingtontimes.com/projects/django-apibuilder/ . Perhaps it can be useful?

/Jesper

๐Ÿ‘คuser84609

0๐Ÿ‘

Have a look at this RestifyDjango.

Somewhat related are Django XML-RPC and JSON-RPC.

๐Ÿ‘คSoviut

0๐Ÿ‘

https://github.com/RueLaLa/savory-pie

Savory Pie is a REST framework that supports django.

๐Ÿ‘คMike Milkin

0๐Ÿ‘

I would suggest you look into Django Rest Framework (DRF), play around with this and see if it suits your requirements. The reason I recommend DRF is because it makes making the API views really simple with the use of GenericAPIView classes, Mixin Classes and Mixed in Generic views. You can easily make use of tried and tested design patterns for making your API endpoints as well as keeping your code base neat and concise. You also DRY when writing your code which is always great. Your API views are literally 2-3 lines long.

You can checkout this tutorial http://programmathics.com/programming/python/django-rest-framework-setup/ that begins from setting up your environment to going through the different ways to make your RESTful API using the django rest framework.

Disclaimer: I am the creator of that website.

๐Ÿ‘คSeekingAlpha

Leave a comment