Skip to main content

Expose Wagtail internals via a REST API for use while developing and testing Wagtail sites.

Project description

Wagtail Exposapi

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

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.

Site requirements

If you are checking a site locally it will work best with a full set of data, so it's best to load staging or development site data.

Try the package locally

This package has a sandbox site that you can use to try it out locally.

  1. Clone the repo
  2. Set up a virtual environment
  3. Run pip install -e '.[modeladmin2]'
  4. Run python manage.py migrate
  5. Run python manage.py load_fixtures
  6. Run python manage.py runserver

Visit http://localhost:8000/exposapi/ to see the default JSON api endpoint for the sandbox or http://localhost:8000/exposapi/?all=1 to see all possible urls for the loaded fixtures.

For admin login use superuser and superuser as the username and password.

Included Base Command

BaseResponsesCommand - A base command that you can extend in your own site to fetch the API data and check the responses.

The default behavior 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 need 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

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

Installation

Install the package with pip:

pip install wagtail-exposapi # coming soon

Before it's released you can install it from this repo:

pip install git+https://github.com/wagtail-packages/wagtail-exposapi.git

Add exposapi to your INSTALLED_APPS in your Django settings file: make sure you really want to enable it in your production site. It doesn't really expose anything sensitive but you may not want to expose your site's internals. You could just add this to your development settings or staging site settings.

Update your urls.py to include the exposapi urls:

urlpatterns = [
    ...,
    path("exposapi/", include("exposapi.urls")),
    ...,
]

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
    ],
}

Tested With

  • Python 3.8, 3.9, 3.10, 3,11, 3.12
  • Django 3.2, 4.0, 4.1, 4.2, 5.0
  • Wagtail 4.1, 4.2, 5.0, 5.1, 5.2, 6.0

Wagtail 5.1 can be used with wagtail-modeladmin 1.0.0 and wagtail 5.2+ can be used with wagtail-modeladmin 2.0.0

Model admin is only required if you still use it in your site.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wagtail-exposapi-1.0.0.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

wagtail_exposapi-1.0.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file wagtail-exposapi-1.0.0.tar.gz.

File metadata

  • Download URL: wagtail-exposapi-1.0.0.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.4

File hashes

Hashes for wagtail-exposapi-1.0.0.tar.gz
Algorithm Hash digest
SHA256 df86ec924dd5bf8cd09c8261dbba863ff45921aa0a1fe6f1bb7e19e9adcfb9e1
MD5 bba0fd269b155c83eaca93241cdaecb7
BLAKE2b-256 6da9633a9fa4300ff67659be377748111a3a311b2c9f7bbfffd39b47fdb36ef2

See more details on using hashes here.

File details

Details for the file wagtail_exposapi-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for wagtail_exposapi-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cc10eb6873e09b54c23ba96c8a9acff4808d3223c50e5be496b29f5094da5f2d
MD5 6cf7a3b12ad1ead0c68ec5441e61450a
BLAKE2b-256 9601394eb1dd81a26cbc232f58b88fcf6cfe99a107642f3797dd8aef318b1362

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page