Update OPTIONS example from “Documenting Your API” (#5680)

Closes #3489

* Updates example to post-3.0 API, using metadata class
* Adds link to metadata docs.
This commit is contained in:
Carlton Gibson 2017-12-19 12:05:46 +01:00 committed by GitHub
parent cc25f57f7b
commit 6560f44912
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -254,16 +254,19 @@ REST framework APIs also support programmatically accessible descriptions, using
When using the generic views, any `OPTIONS` requests will additionally respond with metadata regarding any `POST` or `PUT` actions available, describing which fields are on the serializer.
You can modify the response behavior to `OPTIONS` requests by overriding the `metadata` view method. For example:
You can modify the response behavior to `OPTIONS` requests by overriding the `options` view method and/or by providing a custom Metadata class. For example:
def metadata(self, request):
def options(self, request, *args, **kwargs):
"""
Don't include the view description in OPTIONS responses.
"""
data = super(ExampleView, self).metadata(request)
meta = self.metadata_class()
data = meta.determine_metadata(request, self)
data.pop('description')
return data
See [the Metadata docs][metadata-docs] for more details.
---
## The hypermedia approach
@ -292,3 +295,4 @@ To implement a hypermedia API you'll need to decide on an appropriate media type
[image-apiary]: ../img/apiary.png
[image-self-describing-api]: ../img/self-describing.png
[schemas-examples]: ../api-guide/schemas/#example
[metadata-docs]: ../api-guide/metadata/