The first step to creating a progressive web app (PWA) or single page application (SPA) is enabling Wagtails existing support for a JSONified output. The API module provides a public-facing, JSON-formatted API to allow retrieving content as raw field data. This is useful for cases like serving content to non-web clients (such as a mobile phone app).
Carry out the following instructions to enable the v2 API:
[x] Create a new branch from develop called enable-v2-api. Hint: git checkout -b <new-branch> <existing-branch>
[x] Add the following packages wagtail.api.v2 and rest_framework to your INSTALLED_APPS under base.py
[x] Create a file called api.py next to url.py to hold API configuration e.g API routers , endpoint imports(Pages, Images & Documents) etc
[x] Add an api_router.urls path to url.py above wagtail_urls
[x] Access your API at http://localhost:8000/api/v2/pages/ to verify pages are listed; while the images and documents can be accessed at the /api/v2/images/ and /api/v2/documents/ endpoints respectively.
[x] Commit the changes (as a single commit) .
[x] Push changes to github. Hint:git push --set-upstream origin enable-v2-api
The first step to creating a progressive web app (PWA) or single page application (SPA) is enabling Wagtails existing support for a JSONified output. The API module provides a public-facing, JSON-formatted API to allow retrieving content as raw field data. This is useful for cases like serving content to non-web clients (such as a mobile phone app).
Carry out the following instructions to enable the v2 API:
develop
calledenable-v2-api
. Hint:git checkout -b <new-branch> <existing-branch>
wagtail.api.v2
andrest_framework
to yourINSTALLED_APPS
underbase.py
api.py
next tourl.py
to hold API configuration e.g API routers , endpoint imports(Pages, Images & Documents) etcapi_router.urls
path tourl.py
abovewagtail_urls
images
anddocuments
can be accessed at the/api/v2/images/
and/api/v2/documents/
endpoints respectively.git push --set-upstream origin enable-v2-api
Hint: https://learnwagtail.com/tutorials/how-to-enable-the-v2-api-to-create-a-headless-cms/