From 529d2feb490d7909fc36c260413d6a8af2fa5927 Mon Sep 17 00:00:00 2001
From: 4the4ryushin <aman2001mi@gmail.com>
Date: Tue, 17 Jan 2023 00:52:56 +0530
Subject: [PATCH] Add docs example for how to configure API renderer_classes

- Update docs/advanced_topics/api/v2/configuration.md
- Fixes #6066
- Fix up spelling of customise (UK English not US)
---
 CHANGELOG.txt                                |  1 +
 docs/advanced_topics/api/v2/configuration.md | 16 +++++++++++++++-
 docs/advanced_topics/api/v2/usage.md         |  4 ++--
 docs/releases/4.2.md                         |  1 +
 4 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 73a29984f1..60fb26d1b2 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -87,6 +87,7 @@ Changelog
  * Docs: Fix incorrect example code for StreamField migration of `RichTextField` (Matt Westcott)
  * Docs: Document the policy needed to create invalidations in CloudFront (Jake Howard)
  * Docs: Document how to add permission restriction to a report view (Rishabh jain)
+ * Docs: Add example for how to configure API `renderer_classes` (Aman Pandey)
  * Maintenance: Switch to using Willow instead of Pillow for images (Darrel O'Pry)
  * Maintenance: Remove unsquashed `testapp` migrations (Matt Westcott)
  * Maintenance: Upgrade to Node 18 for frontend build tooling (LB (Ben) Johnston)
diff --git a/docs/advanced_topics/api/v2/configuration.md b/docs/advanced_topics/api/v2/configuration.md
index d6d2ae4b40..9723b7eab5 100644
--- a/docs/advanced_topics/api/v2/configuration.md
+++ b/docs/advanced_topics/api/v2/configuration.md
@@ -44,7 +44,21 @@ Wagtail provides three endpoint classes you can use:
 -   Images {class}`wagtail.images.api.v2.views.ImagesAPIViewSet`
 -   Documents {class}`wagtail.documents.api.v2.views.DocumentsAPIViewSet`
 
-You can subclass any of these endpoint classes to customize their functionality.
+You can subclass any of these endpoint classes to customise their functionality.
+For example, in this case if you need to change the `APIViewSet` by setting a desired renderer class:
+
+```python
+from rest_framework.renderers import JSONRenderer
+
+# ...
+
+class CustomPagesAPIViewSet(PagesAPIViewSet):
+    renderer_classes = [JSONRenderer]
+    name = "pages"
+
+api_router.register_endpoint("pages", ProdPagesAPIViewSet)
+```
+
 Additionally, there is a base endpoint class you can use for adding different
 content types to the API: `wagtail.api.v2.views.BaseAPIViewSet`
 
diff --git a/docs/advanced_topics/api/v2/usage.md b/docs/advanced_topics/api/v2/usage.md
index fcd7a7cb4e..b85793a0f9 100644
--- a/docs/advanced_topics/api/v2/usage.md
+++ b/docs/advanced_topics/api/v2/usage.md
@@ -127,7 +127,7 @@ model. You can read about configuration [here](apiv2_page_fields_configuration).
 ```
 
 This doesn't apply to images/documents as there is only one model exposed in
-those endpoints. But for projects that have customized image/document models,
+those endpoints. But for projects that have customised image/document models,
 the `api_fields` attribute can be used to export any custom fields into the
 API.
 
@@ -523,7 +523,7 @@ the URL. For example:
 -   Documents `/api/v2/documents/1/`
 
 All exported fields will be returned in the response by default. You can use the
-`?fields` parameter to customize which fields are shown.
+`?fields` parameter to customise which fields are shown.
 
 For example: `/api/v2/pages/1/?fields=_,title,body` will return just the
 `title` and `body` of the page with the id of 1.
diff --git a/docs/releases/4.2.md b/docs/releases/4.2.md
index e67aa44629..5b277a041c 100644
--- a/docs/releases/4.2.md
+++ b/docs/releases/4.2.md
@@ -169,6 +169,7 @@ This feature was developed by Matt Westcott, and sponsored by [YouGov](https://y
  * Pull out icon sprite setup function from inline script to its own TypeScript file & add unit tests (Loveth Omokaro)
  * Upgraded Transifex configuration to v3 (Loic Teixeira)
  * Replace repeated HTML `avatar` component with a template tag include `{% avatar ... %}` throughout the admin interface (Aman Pandey)
+ * Add example for how to configure API `renderer_classes` (Aman Pandey)
 
 ## Upgrade considerations