diff --git a/CHANGELOG.txt b/CHANGELOG.txt index b619a6e2a063..90dc3363e0a6 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -86,6 +86,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 d6d2ae4b40e4..9723b7eab57b 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 fcd7a7cb4e3e..b85793a0f973 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 62e5aa3dec8e..19ea1ad40dc9 100644 --- a/docs/releases/4.2.md +++ b/docs/releases/4.2.md @@ -168,6 +168,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