Hi devs,
Context
We need a way for some external tool to use XWiki as a backend and get content from it, edit it locally and push the changes back to XWiki. An example of such a need is Cristal
What’s missing?
Right now you can ask XWiki to get the content in a given syntax (for example using the get
action and outputSyntax
query string parameter). For example you can ask for the HTML version of some doc content. However when you need to update the doc, you need to convert it back to the original syntax (same as what the XWiki WYSIWYG editor is doing), and we don’t have a good REST endpoint for this. And we cannot count on the external tool to have a good conversion feature.
Analysis
I see 3 options:
- Option 1: Introduce a Conversion REST endpoint to convert from a syntax to another. In essence this means moving the current
HTMLConverter.java
,CKEditor.HTMLConverter
,CKEditor.VelocityMacros
, andWysiwygScriptService.java
code into some more generic place and adding a proper REST endpoint. - Option 2: Add a new REST endpoint parameter to the existing
PageResource
endpoint so that you can tell it to convert the received content into a syntax before saving it. - Option 3: Introduce a more specific REST endpoint that extends
PageResource
and adds the conversion feature, likePageConvertResource
.
Option 1:
- Pro: Generic (XWiki can be used as a conversion service for other use cases)
- Cons: Less performant than option 2 since Cristal would need 2 HTTP requests, one to perform the conversion and another one to perform the save. This means passing the full doc content back and forth lots of time.
Option 2:
- Pro: More performant
- Cons: Possibly a bit more contrived since the use case of converting to another syntax could feel something specific and not generic enough to be in the
PageResource
endpoint.
Option 3:
- Pro: Doesn’t have the cons of option 2
- Cons: A bit more code duplication than option 2 but not much
- Cons: More narrow/specific than option 2
- Pro: Performant
Conclusion
My take is that performance is an important aspect so I’d be tempted to go to option 3 (or 2), even if from an architecture POV I prefer option 1.
WDYT?
PS: I’m wondering if GraphQL would allow cleanly chaining operations without the HTTP round trips (ie do it in one pass, and yet still expose 2 REST endpoints: one for conversion and one for saving). I’d need to research this but anyway introducing GraphQL would require another large proposal and is not the goal ATM (yet it’s still interesting to know if GraphQL would provide a solution for this).
Thx