We'll need to define 3 resource handling methods on our resources.
*``PygmentsRoot.get()`` method, which lists all the existing snippets.
*``PygmentsRoot.post()`` method, which creates new snippets.
*``PygmentsInstance.get()`` method, which returns existing snippets.
And set a number of attributes on our resources.
* Set the ``allowed_methods`` and ``anon_allowed_methods`` attributes on both resources allowing for full unauthenticated access.
* Set the ``form`` attribute on the ``PygmentsRoot`` resource, to give us input validation when we create snippets.
* Set the ``emitters`` attribute on the ``PygmentsInstance`` resource, so that
``views.py``
..include:: ../../examples/pygments_api/views.py
:literal:
Completed
---------
And we're done. We now have an API that is:
***Browseable.** The API supports media types for both programmatic and human access, and can be accessed either via a browser or from the command line.
***Self describing.** The API serves as it's own documentation.
***Well connected.** The API can be accessed fully by traversal from the initial URL. Clients never need to construct URLs themselves.
Our API also supports multiple media types for both input and output, and applies sensible input validation in all cases.
For example if we make a POST request using form input: