Our application is on AEM and we have to display data from microservices rest calls on our pages.
Can I directly the services from browser(java script) or do I need to call AEM servlet and let AEM servlet make a http call to microservice.
What is the best practice and what is advantage we get with each of this approach?
Solved! Go to Solution.
Views
Replies
Total Likes
Hi Santhi,
Both the approach which you have mentioned works well. Which one to follow depends on
1. Overall architecture
If you have a proper layered architecture, then it depends on which layer is defined for these API calls.
2. Security
Secondly, I would decide mainly depending on the abstract level I would like to maintain to the browser. If the APIs are open GET API with the generic data, then I would probably call directly from the browser which would be
a) better performance
b) less calls back to publish instance
However, If the data is sensitive and I would like to protect the endpoint exposure to the browser or if there is any authentication required to call the protected API, then I would redirect them via servlet.
a) In this approach, you may have to do more performance tests on your publish instance to make sure your architecture can withstand that traffic.
Hope this gives you some thought process to your question
Thanks!
What is your use case? Do you want to have the data returned from the RESTFUL service displayed on your page? (from your description - sounds like it)
If so, you can write an AEM HTL component that can invoke the service using HTTP Restful call and then parse the response and display the data in the HTL component.
A benefit of using a component is you can control the application logic and parse the data that you want to display in the AEM web page.
Views
Replies
Total Likes
Thanks for the reply.
I see in the example that WCMUsePOJO class is making a http call.
But I want to call the service directly from my java script and display the result.
What is the advantage we get by making a http connection from AEM?
Views
Replies
Total Likes
In many Adobe products like LiveCycle ES to AEM, there is a need to invoke an external service to get data. For example, if you want to get Google Distance Information into your site - you will need to invoke a given Google WS.
In AEM, you can invoke a 3rd party web service using HTTP Java APIs. To use this Java API, you need to code it this way.
THen you can get the result and parse it and display the data in the component's view.
If you prefer to do this using JavaScript, i suppose it can be coded to do the same.
You may even want to look into using HTL JavaScript Use-API
Views
Replies
Total Likes
Yes. We can do both the ways.
We are having huge content to be displayed on pages from making service calls to our micro services.
There is debate on whether to call the services directly from js framework (react or angular) to micro service end point or should the calls be made via osgi bundles(making http connections using apache http client) in AEM.
I want to know what is best practice and why?
Views
Replies
Total Likes
This would all depend on many factors.
How much data is being returned?
How long does a typical call take
how much data do you want to parse and display in the view?
are you building components for an AEM site or are you building a SPA using React?
etc.
I do not believe a single answer will be applicable to each use case. If you are using a SPA and want to do this, then it makes sense to make a call from a JS framework - like Angular.
If you want to display more of a static piece of content - like POSTAL Code data that does not change much - perhaps you can use HTL and Java as shown in the article.
It's best to discuss these concepts with you DEV team and come up with a solution that suits your needs.
Hi Santhi,
Both the approach which you have mentioned works well. Which one to follow depends on
1. Overall architecture
If you have a proper layered architecture, then it depends on which layer is defined for these API calls.
2. Security
Secondly, I would decide mainly depending on the abstract level I would like to maintain to the browser. If the APIs are open GET API with the generic data, then I would probably call directly from the browser which would be
a) better performance
b) less calls back to publish instance
However, If the data is sensitive and I would like to protect the endpoint exposure to the browser or if there is any authentication required to call the protected API, then I would redirect them via servlet.
a) In this approach, you may have to do more performance tests on your publish instance to make sure your architecture can withstand that traffic.
Hope this gives you some thought process to your question
Thanks!
Views
Likes
Replies
Views
Likes
Replies