django-rest-framework/docs/howto/mixin.rst

31 lines
1.2 KiB
ReStructuredText
Raw Normal View History

2011-02-19 16:12:35 +03:00
Using Django REST framework Mixin classes
=========================================
2012-01-03 00:16:44 +04:00
This example demonstrates creating a REST API **without** using Django REST framework's :class:`.Resource` or :class:`.ModelResource`, but instead using Django's :class:`View` class, and adding the :class:`ResponseMixin` class to provide full HTTP Accept header content negotiation,
2011-02-19 16:12:35 +03:00
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:
2012-08-25 22:53:10 +04:00
* http://shielded-mountain-6732.herokuapp.com/mixin/
2011-02-19 16:12:35 +03:00
You can browse the API using a web browser, or from the command line::
2012-08-25 22:53:10 +04:00
curl -X GET http://shielded-mountain-6732.herokuapp.com/mixin/
2011-02-19 16:12:35 +03:00
URL configuration
-----------------
Everything we need for this example can go straight into the URL conf...
``urls.py``
.. include:: ../../examples/mixin/urls.py
:literal:
2012-01-03 00:16:44 +04:00
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.
2011-02-19 16:12:35 +03:00
We even get a nice HTML view which can be used to self-document our API.