This proposal is about providing a rendered version of a page’s content on the /pages endpoint.
XWiki supports many syntaxes, and an application relying on the REST API to fetch knowledge from an XWiki instance might stumble upon pages they don’t know how to handle. This is an issue we have in Cristal currently, since we only support markdown so far (although support for xwiki/2.1 is definitely planned) we require custom code (a XWiki extension) to render content in HTML for all other syntaxes in order to display pages. Having this implemented would help us drop this code to align ourselves with the standard API.
There are at least two ways to implement this if we go with this proposal:
An opt-in boolean flag (renderHtml), that we would always use in Cristal since we cannot know beforehand the syntax of the page we are fecthing,
An optional supportedSyntaxes parameter that, if set, would indicate which syntaxes are supported by the client and thus should not lead to a rendered version. Not setting it at all would not change the current behavior.
Personally, I would prefer option 2 to avoid unnecessary rendering when fetching a page, or avoid fetching it a first time to check its syntax.
I’m not sure I understand the proposal. Isn’t the topic about also returning a rendered version of the page in addition to the raw page content?
If so, then why not simply add an optionalrenderSyntaxes parameters that would list all syntaxes into which the page must be rendered?
Now the main problem is not that, but it’s that for rendering a page you need to know the full context (current language, current user, query string parameters, etc). How are you proposing to pass the context elements?
In the context of Cristal, the goal is to rely on server-side rendering as a fallback when there is no client-side parser available for the page syntax.
In addition, we’d like to do so in the smallest number of queries.
Option 1: introduce a dedicated “rendering” rest endpoint
In this case, we might end up with two rest requests:
call the /pages endpoint (first rest request)
check if we have a parser for the page syntax
if not, call the rendering rest endpoint (second rest request)
Option 2: have the rendering as part of the /pages rest endpoint
get the list of parsers client-side (first and single rest request)
call the /pages rest endpoint and pass the set of supported syntaxes
1.1 if the syntax of the page is part of the supported syntaxes, no rendering is done
1.2 otherwise, the rendering is performed and returns
The advantage of option 2 is that a single query is performed.
The cons is that because of the rendering, the request can be significantly slower to return.
Consequently, part of the UI that could be rendered with the data for the /pages rest endpoint (e.g., breadcrumb), will be blocked waiting for the rendered result too.
Thanks for pointing that out. That’s indeed a point we overlooked when brainstorming the issue.
Do we have documentation of the list of parameters required for rendering?
You should already have the current user and locale in the context (not necessarily in the XWikiContext itself, but it will be found, same as any page /view/).
There is no requirement. It’s more if you need to render the document with a specific context (execute the page with a different current document, in a different current wiki, etc.).