Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

How to store the json from external system

Avatar

Community Advisor

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@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.

 

View solution in original post

4 Replies

Avatar

Community Advisor

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.



Arun Patidar

Avatar

Community Advisor
but the json value could be changed at any time so storing it in conf or content node needs to be scheduled rt..?

Avatar

Community Advisor
yes you need to do sync if needed.


Arun Patidar

Avatar

Correct answer by
Community Advisor

@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.