diff --git a/docs/development/design/embed-api.rst b/docs/development/design/embed-api.rst new file mode 100644 index 00000000000..e736db59565 --- /dev/null +++ b/docs/development/design/embed-api.rst @@ -0,0 +1,221 @@ +Embed API +========= + +The Embed API allows to embed content from docs pages in other sites. +For a while it has been as an *experimental* feature without public documentation or real applications, +but recently it has been used widely (mainly because we created a Sphinx extension). + +This improvement is part of the `CZI grant`_. +Due to this we need to have more friendly to use API, +and general and stable enough to support it for a long time and with external sites. + +.. _CZI grant: https://blog.readthedocs.com/czi-grant-announcement/ + +.. contents:: + :local: + :depth: 3 + +Current implementation +---------------------- + +The current implementation of the API is partially documented in :doc:`/guides/embedding-content`. +Some characteristics/problems are: + +- There are three ways of querying the API, and some rely on Sphinx's concepts like ``doc``. +- Doesn't support MkDocs. +- It returns all sections from the current page on every request. +- Lookups are slow (~500 ms). +- IDs returned aren't well formed (like empty IDs `#`). +- The content is always an array of one element. +- The section can be an identifier or any other four variants or the title of the section. +- It doesn't return valid HTML for definition lists (``dd`` tags without a ``dt`` tag). +- It doesn't support external sites. + +New API +------- + +The API would be split into two endpoints, and only have one way of querying the API. + +Get page +-------- + +Allow us to query information about a page, like its list of sections. + +.. http:get:: /_/api/v3/embed/pages?project=docs&version=latest&path=install.html + + :query project: (required) + :query version: (required) + :query path: (required) + + .. sourcecode:: json + + { + "project": "docs", + "version": "latest", + "path": "install.html", + "title": "Installation Guide", + "url": "https://docs.readthedocs.io/en/latest/install.html", + "sections": [ + { + "title": "Installation", + "id": "installation" + }, + { + "title": "Examples", + "id": "examples" + } + ] + } + +Get section +----------- + +Allow us to query the content of the section, with all links re-written as absolute. + +.. http:get:: /_/api/v3/embed/sections?project=docs&version=latest&path=install.html#examples + + :query project: (required) + :query version: (required) + :query path: Path with or without fragment (required) + + .. sourcecode:: json + + { + "project": "docs", + "version": "latest", + "path": "install.html", + "url": "https://docs.readthedocs.io/en/latest/install.html#examples", + "id": "examples", + "title": "Examples", + "content": "