Skip to main content

Introduction

The Wagtail Bakery Demo provides a RESTful API built on Wagtail’s API v2 framework. The API allows you to programmatically access pages, images, and documents from the CMS.

Base URL

All API endpoints are available under the /api/v2/ base path:
http://localhost:8000/api/v2/

Available Endpoints

The API exposes three main endpoints:
EndpointURLDescription
Pages/api/v2/pages/Access all page content
Images/api/v2/images/Access image assets
Documents/api/v2/documents/Access document files

API Configuration

The API is configured using Wagtail’s WagtailAPIRouter in bakerydemo/api.py:
from wagtail.api.v2.router import WagtailAPIRouter
from wagtail.api.v2.views import PagesAPIViewSet
from wagtail.documents.api.v2.views import DocumentsAPIViewSet
from wagtail.images.api.v2.views import ImagesAPIViewSet

# Create the router with "wagtailapi" namespace
api_router = WagtailAPIRouter("wagtailapi")

# Register endpoints
api_router.register_endpoint("pages", PagesAPIViewSet)
api_router.register_endpoint("images", ImagesAPIViewSet)
api_router.register_endpoint("documents", DocumentsAPIViewSet)

Authentication

The API endpoints are publicly accessible by default. For production deployments, consider implementing authentication and rate limiting.
Currently, the API does not require authentication. All endpoints can be accessed without credentials:
curl http://localhost:8000/api/v2/pages/

Response Format

All API responses are returned in JSON format with the following structure:
meta
object
Metadata about the response, including pagination information
total_count
integer
Total number of items available
items
array
Array of objects matching the query

Example Response

{
  "meta": {
    "total_count": 15
  },
  "items": [
    {
      "id": 1,
      "meta": {
        "type": "home.HomePage",
        "detail_url": "http://localhost:8000/api/v2/pages/1/"
      },
      "title": "Home"
    }
  ]
}

Common Query Parameters

All endpoints support standard query parameters:
limit
integer
default:"20"
Number of items to return per page (max 100)
offset
integer
default:"0"
Number of items to skip before returning results
fields
string
Comma-separated list of fields to include in the response. Use * for all fields.
order
string
Field name to order results by. Prefix with - for descending order.

Example with Parameters

curl "http://localhost:8000/api/v2/pages/?limit=10&fields=*&order=-first_published_at"

Pagination

The API uses limit/offset pagination. Navigate through results using the limit and offset parameters:
# First page (items 0-19)
curl "http://localhost:8000/api/v2/pages/?limit=20&offset=0"

# Second page (items 20-39)
curl "http://localhost:8000/api/v2/pages/?limit=20&offset=20"

Error Responses

API errors are returned with appropriate HTTP status codes:
Status CodeDescription
400Bad Request - Invalid parameters
404Not Found - Resource doesn’t exist
500Internal Server Error

Next Steps

Pages API

Access page content and metadata

Images API

Retrieve image assets and renditions

Documents API

Access document files

Build docs developers (and LLMs) love