Tuesday 6 September 2016

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 a 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 in the AEM web page. 




Join the Experience League

To become an Experience Business, you need more than just great tools and online help. You need a partner. Experience League is a new enablement program with guided learning to help you get the most out of Adobe Experience Cloud. With training materials, one-to-one expert support, and a thriving community of fellow professionals, Experience League is a comprehensive program designed to help you become your best.

Join the Adobe Experience League by clicking this banner.




I (Scott Macdonald) am a Senior Experience League Community Manager at Adobe Systems with 20 years in the high tech industry. I am also a programmer with knowledge in Java, JavaScript, C#,C++, HTML, XML and ActionScript. If  you would like to see more AEM or other end to end articles like this, then leave a comment and let me know what content you would like to see.


Twitter: Follow the Digital Marketing Customer Care team on Twitter @AdobeExpCare.