Skip to content

Add API to expose toolbar data #2048

Open
@robhudson

Description

Summary:

Enhance the Django Debug Toolbar by providing an API to expose collected debug data. This API will enable new UIs to interact with the debug information programmatically, especially useful for API-only Django projects or cases where injecting HTML interferes with the application's frontend.


Proposal:

Add two initial API endpoints, building upon the serializable branch, which already stores collected debug stats as JSON in pluggable storage.

  1. Get All Request IDs and Basic Info

    • Endpoint to retrieve a list of all available request_ids along with some basic metadata about each request, similar to the current history panel.
    • GET /__debug__/api/requests/
  2. Get Full Data for a Specific Request

    • Endpoint to retrieve all debug data collected for a given request_id.
    • GET /__debug__/api/requests/<str:request_id>/

Motivation:

Currently, the Django Debug Toolbar injects an HTML interface into pages for debugging. However:

  • For API-only Django projects, there's no user interface to display debug data.
  • In projects with custom or complex frontends, injecting HTML can interfere with functionality or styling.
  • A programmatic API enables developers to build custom debugging UIs tailored to their needs.

This API will provide greater flexibility and usability for a wider range of projects while leveraging the existing serializable storage architecture.


Implementation Details:

  1. Base the API on the serializable branch:
    • The debug stats are already stored as JSON in pluggable storage, making it straightforward to expose this data via an API.
  2. Consider Pagination:
    • For the /requests/ endpoint, if there are many requests, pagination can be implemented to improve performance and usability.
    • Pagination can be implemented within the pluggable storage classes from the serializable branch, as the method of pagination will likely depend on the specific storage backend being used.

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions