From b94582e4a6605d6567fae6fa176f3aa536834400 Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Tue, 19 Dec 2017 09:55:31 +0100 Subject: [PATCH] =?UTF-8?q?Update=20OPTIONS=20example=20from=20=E2=80=9CDo?= =?UTF-8?q?cumenting=20Your=20API=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #3489 * Updates example to post-3.0 API, using metadata class * Adds link to metadata docs. --- docs/topics/documenting-your-api.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/topics/documenting-your-api.md b/docs/topics/documenting-your-api.md index 425b02eb89..ae592e6369 100644 --- a/docs/topics/documenting-your-api.md +++ b/docs/topics/documenting-your-api.md @@ -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/ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy