I need to expose an API endpoint in the html documents, so I can later do client-side rest calls (for search and/or subsequent pagination).
As the JS needs to stay agnostic of config files, I suppose that the
<head> of the document with an appropriate
<link> tag should be the go-to place. So something like:
<link rel="???" type="application/json" href="https://example.com/api" />
Looking through Mozilla docs and the Microformats' list, I found no obvious match.
Close candidates may be:
rel="alternate" - "Alternate representations of the current document"
With the issue being that this is not a 'substitute version' for each document, rather a general resource. Feeds often use it like this, with all iterations pointing back to a single xml origin file or api, but I suppose that's not quite proper.
rel="search" - "Gives a link to a resource that can be used to search through the current document and its related pages."
Almost makes sense for the current use case, but not quite so for a generic api endpoint (that may not even allow search at all).
rel="index" - "Refers to a document providing a list of topics with pointers that pertain to the current document."
It could be argued that indeed an api holding the full resources may serve as an index for the parts actually displayed, especially with pagination as originally intended, but it seems a bit far-fetched and, again, it'd be rather particular to this use case.
Not so close candidates:
rel="https://example.com/api" - Not supported in any spec, only brief mention that Wordpress does it like this, with the
rel="https://api.w.org/" random namespace. Does not validate.
rel="api" - Sounds fit and appropriate, thought i'd try it in a validator, no luck.
meta property="api" content="https://example.com/api" - Improperly use a meta for the link, with whatever name or property (OG/FB style) - does validate but is still just random repurposing.
So is there any standard or accepted practice for this?