I’d like to create a page [“content”] that’s going to display some JSON. The JSON response is dependent on the type of HTTP request, and it is supposed to be generated by the part.
What’s the suggested, scalable solution to this problem in Enonic XP 6.0.0?
I would imagine a solution in which I can use the Enonic XP admin interface to drag a JSON part onto a JSON page region. However, as the page is going to display JSON, and this JSON view is also present in the admin view, drag and drop in the admin interface seems cumbersome…
To be able to use the part in Live Edit (when editing the page in admin), the part output needs to be HTML. But you could check the rendering mode in the part controller, and if request.mode == 'edit' then return the JSON wrapped in a <textarea> or <pre> tag, otherwise return the plain JSON and set contentType='application/json'.
Maybe a service would be better. You can make a service to have a URL endpoint that will handle POST and/or GET and do whatever you want and then return dynamic JSON.