[DOCU-678] Document how to create a json-provider using magnolia templating Created: 24/Feb/16  Updated: 29/May/18  Resolved: 28/May/18

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Story Priority: Neutral
Reporter: Christopher Zimmermann Assignee: Christoph Meier
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
dependency
Template:
Acceptance criteria:
Empty
Date of First Response:

 Description   

Rest module provides out of the box rest endpoints and the abilty to define custom endpoints.

But there is another technique that customers use which is to use a page template to output json (or maybe xml as well) instead of html.
Key advantage is that a template writer uses all the same skills and techniques to effectively create a rest endpoint. They just write the script to output the json format instead of html.
Im not sure what other configuration is necessary, but I know Tomas has employed this technique.
Also it is written about in this blog post:
https://www.magnolia-cms.com/blogs/jan-haderka/detail~@json--rest--magnolia-and-the-creation-of-end-points-without-writing-a-single-line-of-java~.html

There are other advantages - such as you dont need to setup additional security to get it to work.
And translation typically works out of the box.



 Comments   
Comment by Christoph Meier [ 24/Feb/16 ]

Theoretically i got the point.
So, it is about producing json or xml by just using freemarker - which allows to have kind of custom-endpoint replacement without any java. In a "real world example" i never ever would do that just with freemarker. (Instead i would use neat-jsonfn at 1st place and freemarker with a java model on 2nd place.)
But, okay, if it is a high-level goal to do things without Java - creating custom-endpoint replacement with freemarker only makes sense.

Comment by Christopher Zimmermann [ 24/Feb/16 ]

Yeah - I would just explain the basic principle that a template can output json.
And then build on that with an example of simple ftl.
And then build on that with the option to create a model class.

Comment by Christopher Zimmermann [ 24/Feb/16 ]

I would ask Tomas about the other differences to REST module endpoints - ie security and translation. But missing the rest-tools support that the REST module provides.

Comment by Christoph Meier [ 02/Dec/16 ]

Since jsonfn comes closer and closer to the product moving into the Magnolia repo too - now i even more believe that jsonfn is the way to go.
However, a page Creating a json-provider using magnolia templating still makes a lot of sense, but it will recommend using jsonfn and just a few tiny bits hot to do it without jsonfn, etc. pp.
I highly guess everybody who ever was creating template based json providers would i agree.

Comment by Christoph Meier [ 25/Apr/17 ]

czimmermann, as you have seen jsonfn docs are out now.
Besides that, i know that PM / PD is planning to improve the REST API.
That's why i wonder whether this ticket is still valid.
-
However, i still would have few nice ideas and hints for an LD-only json-provider - which could be summarized on a page.

Comment by Christopher Zimmermann [ 25/Apr/17 ]

Good question, but yes this ticket is still valid. I think it could be addressed without too much actual text. jsonfn ref is useful. REST api docs are useful. But I see the need for an overview of the whole topic - mentioning the different approaches and when you would use them.
Even once the new REST is available, I think there may still be use cases for jsonfn and this approach.
For example: Jan S. and Tomas have an interesting approach with a component that has two templates - one for first load and HTML, and a variant one for generating the json required for the component.

Comment by Christopher Zimmermann [ 25/Apr/17 ]

Good that you raise this because we should have this in place in time for Q3 marketing theme. (july 1 at the latest)

Comment by Christoph Meier [ 26/Apr/17 ]

czimmermann atm rather needs what is filed in DOCU-1006.
This ticket (DOCU-678) now has a really low prio. Very well possible that it will be closed as obsolete, let's see.

Comment by Christoph Meier [ 28/May/18 ]

I would say that's now tackled with https://documentation.magnolia-cms.com/display/DOCS56/How+to+get+content+as+JSON+-+an+overview
So I close this (again?).

Comment by Christopher Zimmermann [ 29/May/18 ]

Definitely. thumbs up.

Generated at Mon Feb 12 01:11:23 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.