diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/examples/blogpost.rst | 2 | ||||
| -rw-r--r-- | docs/examples/objectstore.rst | 2 | ||||
| -rw-r--r-- | docs/index.rst | 37 |
3 files changed, 40 insertions, 1 deletions
diff --git a/docs/examples/blogpost.rst b/docs/examples/blogpost.rst index 067a6bb3..aeb3d2fd 100644 --- a/docs/examples/blogpost.rst +++ b/docs/examples/blogpost.rst @@ -1,6 +1,8 @@ ModelResource example - Blog posts ================================== +* http://api.django-rest-framework.org/blog-post/ + The models ---------- diff --git a/docs/examples/objectstore.rst b/docs/examples/objectstore.rst index be65a3b7..05c750c5 100644 --- a/docs/examples/objectstore.rst +++ b/docs/examples/objectstore.rst @@ -1,6 +1,8 @@ Resource example - An object store ================================== +* http://api.django-rest-framework.org/object-store/ + ``urls.py`` .. include:: ../../examples/objectstore/urls.py diff --git a/docs/index.rst b/docs/index.rst index 7da3f017..8b273dd7 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -41,7 +41,26 @@ Getting Started --------------- Often you'll want parts of your API to directly map to existing Models. -At it's simplest this looks something like this... +Typically that might look this looks something like this... + +``models.py`` + +.. code-block:: python + + from django.db import models + + class MyModel(models.Model): + foo = models.BooleanField() + bar = models.IntegerField(help_text='Must be an integer.') + baz = models.CharField(max_length=32, help_text='Free text. Max length 32 chars.') + created = models.DateTimeField(auto_now_add=True) + + class Meta: + ordering = ('created',) + + @models.permalink + def get_absolute_url(self): + return ('simpleexample.views.MyModelResource', (self.pk,)) ``urls.py`` @@ -53,6 +72,22 @@ At it's simplest this looks something like this... .. include:: ../examples/simpleexample/views.py :literal: +And we're done. We've now got a fully browseable API, which supports multiple input and output media types, and has all the nice automatic field validation that Django gives us for free. + +We can visit the API in our browser: + +* http://api.django-rest-framework.org/simple-example/ + +Or access it from the command line using curl: + +.. code-block:: bash + + bash: curl -X POST -H 'X-Requested-With: XMLHttpRequest' --data 'foo=bar' http://api.django-rest-framework.org/simple-example/ + {"detail": {"bar": ["This field is required."], "baz": ["This field is required."]}} + +.. note:: + + TODO: Mention adding custom handler methods, but that the defaults will often do what we want already. Document a Resource example, not tied to models. Examples -------- |
