diff options
Diffstat (limited to 'docs/howto')
| -rw-r--r-- | docs/howto/mixin.rst | 30 | ||||
| -rw-r--r-- | docs/howto/setup.rst | 28 | ||||
| -rw-r--r-- | docs/howto/usingcurl.rst | 6 |
3 files changed, 59 insertions, 5 deletions
diff --git a/docs/howto/mixin.rst b/docs/howto/mixin.rst new file mode 100644 index 00000000..68a73690 --- /dev/null +++ b/docs/howto/mixin.rst @@ -0,0 +1,30 @@ +Using Django REST framework Mixin classes +========================================= + +This example demonstrates creating a REST API **without** using Django REST framework's :class:`.Resource` or :class:`.ModelResource`, +but instead using Django :class:`View` class, and adding the :class:`EmitterMixin` class to provide full HTTP Accept header content negotiation, +a browseable Web API, and much of the other goodness that Django REST framework gives you for free. + +.. note:: + + A live sandbox instance of this API is available for testing: + + * http://api.django-rest-framework.org/mixin/ + + You can browse the API using a web browser, or from the command line:: + + curl -X GET http://api.django-rest-framework.org/mixin/ + + +URL configuration +----------------- + +Everything we need for this example can go straight into the URL conf... + +``urls.py`` + +.. include:: ../../examples/mixin/urls.py + :literal: + +That's it. Auto-magically our API now supports multiple output formats, specified either by using standard HTTP Accept header content negotiation, or by using the `&_accept=application/json` style parameter overrides. +We even get a nice HTML view which can be used to self-document our API. diff --git a/docs/howto/setup.rst b/docs/howto/setup.rst new file mode 100644 index 00000000..97b9e6d4 --- /dev/null +++ b/docs/howto/setup.rst @@ -0,0 +1,28 @@ +.. _setup: + +Setup +===== + +Template Loaders +---------------- + +Django REST framework uses a few templates for the HTML and plain text documenting emitters. + +* Ensure ``TEMPLATE_LOADERS`` setting contains ``'django.template.loaders.app_directories.Loader'``. + +This will be the case by default so you shouldn't normally need to do anything here. + +Admin Styling +------------- + +Django REST framework uses the admin media for styling. When running using Django's testserver this is automatically served for you, but once you move onto a production server, you'll want to make sure you serve the admin media seperatly, exactly as you would do if using the Django admin. + +* Ensure that the ``ADMIN_MEDIA_PREFIX`` is set appropriately and that you are serving the admin media. (Django's testserver will automatically serve the admin media for you) + +Markdown +-------- + +The Python `markdown library <http://www.freewisdom.org/projects/python-markdown/>`_ is not required but comes recommended. + +If markdown is installed your :class:`.Resource` descriptions can include `markdown style formatting <http://daringfireball.net/projects/markdown/syntax>`_ which will be rendered by the HTML documenting emitter. + diff --git a/docs/howto/usingcurl.rst b/docs/howto/usingcurl.rst index a1f748c1..e7edfef9 100644 --- a/docs/howto/usingcurl.rst +++ b/docs/howto/usingcurl.rst @@ -17,11 +17,7 @@ There are a few things that can be helpful to remember when using CURL with djan curl -X GET -H 'Accept: text/plain' http://example.com/my-api/ -#. All POST requests should include an ```X-Requested-With: XMLHttpRequest`` header <http://docs.djangoproject.com/en/dev/ref/contrib/csrf/#how-it-works>`_:: - - curl -X POST -H 'X-Requested-With: XMLHttpRequest' --data 'foo=bar' http://example.com/my-api/ - -#. ``POST`` and ``PUT`` requests can contain form data (ie ``Content-Type:: application/x-www-form-urlencoded``):: +#. ``POST`` and ``PUT`` requests can contain form data (ie ``Content-Type: application/x-www-form-urlencoded``):: curl -X PUT --data 'foo=bar' http://example.com/my-api/some-resource/ |
