Package: wagtail-exposapi
Wagtail ExposapiWagtail Exposapi is a Wagtail plugin that provides a JSON API for your Wagtail sites internals.Usage SuggestionWhen 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 requirementsIf 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 locallyThis package has a sandbox site that you can use to try it out locally.Clone the repoSet up a virtual environmentRunpip install -e '.[modeladmin2]'Runpython manage.py migrateRunpython manage.py load_fixturesRunpython manage.py runserverVisithttp://localhost:8000/exposapi/to see the default JSON api endpoint for the sandbox orhttp://localhost:8000/exposapi/?all=1to see all possible urls for the loaded fixtures.For admin login usesuperuserandsuperuseras the username and password.Included Base CommandBaseResponsesCommand- 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:--expandedincludes the 200 responses in the output,--allincludes 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 aresuperuserfor the username and password andhttp://localhost:8000for the url and/admin/login/for the login path.Create a new command in your site that extendsBaseResponsesCommand.fromexposapi.responses_commandimportBaseResponsesCommandclassCommand(BaseResponsesCommand):passFor convenience you can add default options to the command so you don't need to type them each time you run the command.classCommand(BaseResponsesCommand):# you might want to fetch these from environment variablesusername="your-login-username"password="your-login-password"url="http://localhost:8000"# the base url of your sitelogin_path="/admin/login/"# the login url for your siteInstallationInstall the package with pip:pipinstallwagtail-exposapi# coming soonBefore it's released you can install it from this repo:pipinstallgit+https://github.com/wagtail-packages/wagtail-exposapi.gitAddexposapito yourINSTALLED_APPSin 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 yoururls.pyto include the exposapi urls:urlpatterns=[...,path("exposapi/",include("exposapi.urls")),...,]ConfigurationIf 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 WithPython 3.8, 3.9, 3.10, 3,11, 3.12Django 3.2, 4.0, 4.1, 4.2, 5.0Wagtail 4.1, 4.2, 5.0, 5.1, 5.2, 6.0Wagtail 5.1 can be used with wagtail-modeladmin 1.0.0 and wagtail 5.2+ can be used with wagtail-modeladmin 2.0.0Model admin is only required if you still use it in your site.