Skip to content

Commit

Permalink
Add docs example for how to configure API renderer_classes
Browse files Browse the repository at this point in the history
- Update docs/advanced_topics/api/v2/configuration.md
- Fixes wagtail#6066
- Fix up spelling of customise (UK English not US)
  • Loading branch information
salty-ivy authored and lb- committed Jan 19, 2023
1 parent cc0f2d7 commit b511c59
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 15 additions & 1 deletion docs/advanced_topics/api/v2/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
4 changes: 2 additions & 2 deletions docs/advanced_topics/api/v2/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions docs/releases/4.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b511c59

Please sign in to comment.