How to store the json from external system

ka786 09-03-2020

Hi Team,

 

We have a requirement where in we need to ca ll a 3rd party rest api to get a json response based on which we need to construct all the components on the page.

 

So my question is how shall we call the 3rd party api only once and then all the components use the same json response .

 

Please let us know the correct way of handling this scenario.

Note: we are not using SPA.

 

Regards

Accepted Solutions (1)

Accepted Solutions (1)

Briankasingli 09-03-2020

@ka 

When dealing with third-party APIs, the best practice is to always think of the best way to offload the server-load from your publishers. Ask questions like: does does this third-party API need to be a par of the HTML within the server-side render? If server-side render is not required, you can invoke the third-party API using Javascript, and with the response, using Javascript to render HTML elements to the page. This practice will keep your AEM publishers more performant and unblocked.

Read more here: https://sourcedcode.com/scenario-building-aem-components-with-3rd-party-integrations-the-right-way

In my experience, the best way to deliver a performant AEM website is to cache all pages. Try migrating all the content from the old CMS to AEM; in this case, you can utilise the Apache Sling Framework to do all the heavy lifting for you. Take a look at the custom data importer service, com.day.cq.polling.importer.Importer API.

 

Answers (1)

Answers (1)

Arun_Patidar
MVP
09-03-2020

You can make a request using HttpClient Api from sling servlet/services and store json inside /conf if not exposing to client, otherwise store inside content and use this json.

I would suggest parse/store this json as node, would be easy to access and use later.