April 14, 2020
Estimated Post Reading Time ~

Creating an AEM HTML Template Language Component that displays data from a Restful Web Service

You can create an Adobe Experience Manager (AEM) HTML Template Language (HTL) component that displays data retrieved from a third-party Restful web service. For example, assume you want to display data based on the distance between two cities on your web site. In this situation, you can develop an AEM HTL component that displays data between two cities, as shown in this illustration.



In this use case, the HTL component contains a class that extends WCMUsePojo. This class uses Java application logic to send an HTTP Request to a third-party Restful web service. The web service returns the following data in JSON format.

{
"destination_addresses":[
"Dallas, TX, USA"
],
"origin_addresses":[
"Ottawa, ON, Canada"
],
"rows":[
{
"elements":[
{
"distance":{
"text":"2,714 km",
"value":2713758
},
"duration":{
"text":"1 day 1 hour",
"value":89044
},
"status":"OK"
}
]
}
],
"status":"OK"
}

The HTL component uses the Java library GSON to parse the JSON data and then displays the data in the client so it appears on the AEM web page.

To read this development article for AEM 6.2, click https://helpx.adobe.com/experience-manager/using/restful_htl.html.

To read this development article for AEM 6.3, click https://helpx.adobe.com/experience-manager/using/restful_aem63.html.


By aem4beginner

No comments:

Post a Comment

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