Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Options to store JSON response

Avatar

Level 3

Hi All,

We have requirement where we will have get all the products, accessories, and other information to the products. We are using tags and would like to use queries to get all the info and store in json format to cache in dispatcher. 

 

I can do this in AEM servlet where we can write all the business logic, generate JSON when we request servlet. But calling servlet from sling model is not good idea. could you please advise what are the options we have to generate JSON and cache in dispatcher? 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

yeah, your ajax call will go to the servlet which returns json.

https://www.w3schools.com/js/tryit.asp?filename=tryjs_ajax_first

 



Arun Patidar

View solution in original post

5 Replies

Avatar

Community Advisor

You can generate json and cache at the dispatcher and use front end logic to generate presentation using this json.



Arun Patidar

Avatar

Level 3

@arunpatidar , we are thinking to write business logic in servlet so that we can cache at the servlet json at dispatcher level but the question is how can we refer the sling servlet in Sling Model level to read the json and pass data back to sightly.  

 

Are you saying to make a call to servlet from front end (javascript directly ) without interacting with sling Model? 

Avatar

Community Advisor

Hi @SonuR1 

Yes, you can directly make a request from front end to servlet without interacting with sling Model.

Small business logic can also be done at front end if needed and the other backend configuration can also be exposed as data-attribute in HTL using sling model



Arun Patidar

Avatar

Level 3

@arunpatidar you mean, make Ajax call and get response in javascript and pass the data from javascript to sightly ? 

would be great if you can share any examples code snippets. 

Avatar

Correct answer by
Community Advisor

yeah, your ajax call will go to the servlet which returns json.

https://www.w3schools.com/js/tryit.asp?filename=tryjs_ajax_first

 



Arun Patidar