#. `django-piston <https://bitbucket.org/jespern/django-piston/wiki/Home>`_ is excellent, and has a great community behind it. This project is based on piston code in parts.
#. `django-tasypie <https://github.com/toastdriven/django-tastypie>`_ is also well worth looking at.
Django REST framework is a lightweight REST framework for Django.
It aims to make it easy to build well-connected, self-describing Web APIs with a minimum of fuss.
Features:
...
...
@@ -45,16 +47,16 @@ To add django-rest-framework to a django project:
* Add ``djangorestframework`` to your ``INSTALLED_APPS``.
* Ensure the ``TEMPLATE_LOADERS`` setting contains the item ``'django.template.loaders.app_directories.Loader'``. (It will do by default, so you shouldn't normally need to do anything here.)
Getting Started - Resource
--------------------------
Getting Started - Resources
---------------------------
We're going to start off with a simple example, that demonstrates
a few things:
* Creating resources
* Linking resources
* Writing method handlers on resources
* Adding form validation to resources
#. Creating resources.
#. Linking resources.
#. Writing method handlers on resources.
#. Adding form validation to resources.
First we'll define two resources in our urlconf.
...
...
@@ -77,27 +79,44 @@ Now we'll write our resources. The first is a read only resource that links to
.. include:: ../examples/resourceexample/views.py
:literal:
That's us done.
That's us done. Our API now provides both programmatic access using JSON and XML, as well a nice browseable HTML view:
Here's the models we're working from in this example. It's usually a good idea to make sure you provide the :func:`get_absolute_url()` `permalink <http://docs.djangoproject.com/en/dev/ref/models/instances/#get-absolute-url>`_ for all models you want to expose via the API.
Now that we've got some models and a urlconf, there's very little code to write. We'll create a :class:`.ModelResource` to map to instances of our models, and a top level :class:`.RootModelResource` to list the existing instance and to create new instances.
{"detail": {"bar": ["This field is required."], "baz": ["This field is required."]}}
We could also have added the handler methods get(), post() etc... seen in the last example, but Django REST framework provides nice default implementations for us that do exactly what we'd expect them to.
We could also have added the handler methods :meth:`.Resource.get()`, :meth:`.Resource.post()` etc... seen in the last example, but Django REST framework provides nice default implementations for us that do exactly what we'd expect them to.
Examples
--------
...
...
@@ -140,17 +161,14 @@ All the examples are freely available for testing in the sandbox here: http://ap