Wagtail Exposapi

Wagtail Exposapi is a Wagtail plugin that provides a JSON API for your Wagtail sites internals.

Installation and usage details can be read here: https://github.com/wagtail-packages/wagtail-exposapi

This is a re-work of the Response Checker I created earlier and that command is still available in this package.

I have also created a stand alone click cli package that can be used in place of the command. CLI on github

Usage Suggestion

When installed a JSON API view will list all:

  • admin listing page urls.
  • at least one of all edit page urls for installed Wagtail core apps.
  • at least one of all edit page type urls for your own models in installed apps.
  • at least one of all page type views for your own models in installed apps.

It does this with zero configuration. If need be you can provided configuration to exclude models or apps or provide a full list of apps/models to work with.

With this information it's possible to make a get request to each URL and check the response using various external tools or scripts e.g.

  • use a tool like Postman to check the responses.
  • create a script to check the responses.
  • use a monitoring service to check the responses.
  • use a CI/CD pipeline to check the responses.
  • and so on.

Included Base Command

The package includes a base command that you can extend in your own site to fetch the API data and check the responses while developing your site.

This is especially useful if you have upgraded your wagtail site to a new version and want to make sure you've covered the upgrade points around views and templates.

The default behaviour is to report any urls that return a response code other than 200.

You can add options to see more details: --expanded includes the 200 responses in the output, --all includes all responses endpoints in a site (could be slow depending the size of the size).

The command needs to be able to login to the site so you need to provide a --username, --password and --url and --login-path, the defaults are superuser for the username and password and http://localhost:8000 for the url and /admin/login/ for the login path.

Create a new command in your site that extends BaseResponsesCommand.

from exposapi.responses_command import BaseResponsesCommand

class Command(BaseResponsesCommand):
    pass
python
note code Copy code

For convenience you can add default options to the command so you don't need to type them each time you run the command.

class Command(BaseResponsesCommand):
    # you might want to fetch these from environment variables
    username = "your-login-username"
    password = "your-login-password"
    url = "http://localhost:8000"  # the base url of your site
    login_path = "/admin/login/"  # the login url for your site
python
note code Copy code

Configuration

If you want to customise the introspection you can provide the configuration shown below.

EXPOSAPI_CONFIG = {
    "base_url": "http://localhost:8000",
    "listing_exclude": [
        "wagtailimages",
        ...,  # these apps won't be included in the listing pages
    ],
    "listing_pages_config": [
        {
            "title": "Search promotions",
            "app_name": "wagtailsearchpromotions",
            "listing_name": "wagtailsearchpromotions:index",
        },
        {
            "title": "Forms",
            "app_name": "wagtailforms",
            "listing_name": "wagtailforms:index",
        },
        ...,  # these will override the introspection for the listing pages
    ],
    "apps_exclude": [
        "wagtailimages",
        ...,  # these apps won't be included in the edit pages
    ],
}
python
note code Copy code