March 22, 2020
Estimated Post Reading Time ~

Create Content Service End point in AEM 6.4

Content Services & its use
Content Services enable the creation of Page-based HTTP end-points. This endpoint helps to render the content to a normalized JSON format.

How to configure & access the content services in AEM 6.4?

We need to configure content service endpoints whenever we need to export Content Fragment data to external applications(Like Single Page Application or mobile app etc). Let us see how it can be done. The endpoint pages are not to be accessed as HTML pages, they just export the content in JSON format.

Say we have master, mobile, tab variations as shown below.


[Mobile & Tab Content Fragment]


Go to Sites> We-retail, click on 'Create' > 'Page'
Enter details as below and click on create. A new page will be created. (/content/we-retail/content-service-for-sample-fragment.html)


Open the page and author the content fragment on this page(Steps are explained in my previous post).


As you see, I have authored master, variation1(Mobile), Variation 2 (Tab) in the same page.

Now go to the page url and append '.model.json' to invoke JSON exporter. (In my case: content-service-for-sample-fragment.model.json). You can see the JSON with all variations included. 



[JSON portion of Content Fragment for Mobile]


[JSON format for tablet]

From this JSON, we can iterate over the content fragments section and by checking for the variation, we can render items across various channels.

Remember I have authored the Content Fragment utilizing an existing we-retail template. So the JSON will have all related items like header, footer, etc. In real projects, create a stand-alone template and then create a page from this.



By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.