Link rel=alternate header for tables and rows

Also added Access-Control-Expose-Headers: Link to --cors mode.

Closes #1533

Refs https://github.com/simonw/datasette-notebook/issues/2

LL#	metadata.json.1
This commit is contained in:
Simon Willison 2021-11-27 12:08:42 -08:00
commit 3ef47a0896
9 changed files with 86 additions and 6 deletions

View file

@ -14,6 +14,7 @@ served with the following additional HTTP headers::
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Authorization
Access-Control-Expose-Headers: Link
This means JavaScript running on any domain will be able to make cross-origin
requests to fetch the data.
@ -435,3 +436,22 @@ looks like::
The column in the foreign key table that is used for the label can be specified
in ``metadata.json`` - see :ref:`label_columns`.
.. _json_api_discover_alternate:
Discovering the JSON for a page
-------------------------------
The :ref:`table <TableView>` and :ref:`row <RowView>` HTML pages both provide a mechanism for discovering their JSON equivalents using the HTML ``link`` mechanism.
You can find this near the top of those pages, looking like this:
.. code-block:: python
<link rel="alternate"
type="application/json+datasette"
href="https://latest.datasette.io/fixtures/sortable.json">
The JSON URL is also made available in a ``Link`` HTTP header for the page::
Link: https://latest.datasette.io/fixtures/sortable.json; rel="alternate"; type="application/json+datasette"