|
| 1 | +RFC 8288 Link Header & Pagination |
| 2 | +================================= |
| 3 | + |
| 4 | +Paginated REST APIs return ``Link: <...>; rel="next"`` headers, but nothing |
| 5 | +parsed them, so multi-page fetches needed manual glue. This parses the header |
| 6 | +(handling quoted parameter values and multiple links), indexes links by their |
| 7 | +relation, and walks ``rel="next"`` over an injected transport. |
| 8 | + |
| 9 | +Pure standard library (``re``); imports no ``PySide6``. The parser is pure and |
| 10 | +``paginate`` takes an injected ``fetch`` callable, so pagination is CI-testable |
| 11 | +without a live server. |
| 12 | + |
| 13 | +Headless API |
| 14 | +------------ |
| 15 | + |
| 16 | +.. code-block:: python |
| 17 | +
|
| 18 | + from je_auto_control import parse_link_header, next_url, links_by_rel, paginate |
| 19 | +
|
| 20 | + header = '<https://api/x?page=2>; rel="next", <https://api/x?page=9>; rel="last"' |
| 21 | + links = parse_link_header(header) # [Link(uri=..., rel="next"), ...] |
| 22 | + nxt = next_url(header) # "https://api/x?page=2" |
| 23 | + last = links_by_rel(header)["last"].uri |
| 24 | +
|
| 25 | + # Walk every page over an injected fetch (transport / cassette): |
| 26 | + pages = paginate(start_url, fetch, max_pages=50) |
| 27 | +
|
| 28 | +``parse_link_header`` returns a list of ``Link`` (``uri``, ``rel``, and all |
| 29 | +``params``), tolerating quoted values that contain commas and multiple links in |
| 30 | +one header. ``links_by_rel`` indexes by each (space-separated) relation, |
| 31 | +``next_url`` is the ``rel="next"`` convenience, and ``paginate`` fetches a URL |
| 32 | +and follows ``next`` links via the supplied ``fetch`` callable up to |
| 33 | +``max_pages``. |
| 34 | + |
| 35 | +Executor commands |
| 36 | +----------------- |
| 37 | + |
| 38 | +``AC_parse_link_header`` parses a header ``value`` into ``{links}``; |
| 39 | +``AC_next_url`` returns ``{url}`` for ``rel="next"``. Both are exposed as MCP |
| 40 | +tools (``ac_parse_link_header`` / ``ac_next_url``) and as Script Builder |
| 41 | +commands under **Data**. |
0 commit comments