Expand my Community achievements bar.

SOLVED

Consume Api OSGI service

Avatar

Level 2

Hello, I need to consume APIs using AEM, I know it is possible to do it using OSGI service but I can't find any documentation or tutorial showing how to do it. The idea is to use the API through Java, and pass it through a varival to the ui.frontend. Today I use MapTo to do this communication, it works really well.

1 Accepted Solution

Avatar

Correct answer by
Level 5

Generally, we prefer to call the APIs from FE, you can use a Dispatcher proxy to do that. Refer to this URL to understand why AEM is not preferred to use as a proxy to make API calls. https://cqdump.joerghoh.de/2024/06/27/do-not-use-aem-as-a-proxy-for-backend-calls/. If you still need to use it for implementing some business logic refer to this URL -https://kiransg.com/2021/11/08/aem-rest-service-using-http-client-factory/ 

View solution in original post

5 Replies

Avatar

Community Advisor

Hi @ElvisRo ,

I am not sure why you have to call API thru java back-end, but by considering performance in mind, you should call the api from the front-end only. 
Normally we keep api endpoints and credentials in a form of OSGI configuration and read it from there and pass it to front-end for for further execution.

To Configure OSGI please see the video 

https://experienceleague.adobe.com/en/docs/experience-manager-learn/cloud-service/developing/basics/...
If you are using AEM as cloud service you can take help from Environment variable as well if it suites your requirement.

Hope this helps

Umesh Thakur

Avatar

Level 2

I intend to keep the call only on the Front-end, but I had already seen recommendations for OSGi.
So I won't get blocked by something from AEM if I do this on the front-end in ui.front-end, right?

Avatar

Community Advisor

You can make call from OSGI service that is totally fine but keep in mind, back-end call is expensive.

is it possible to share the recommendations or the exact meaning of OSGI, you are referring to?

Avatar

Correct answer by
Level 5

Generally, we prefer to call the APIs from FE, you can use a Dispatcher proxy to do that. Refer to this URL to understand why AEM is not preferred to use as a proxy to make API calls. https://cqdump.joerghoh.de/2024/06/27/do-not-use-aem-as-a-proxy-for-backend-calls/. If you still need to use it for implementing some business logic refer to this URL -https://kiransg.com/2021/11/08/aem-rest-service-using-http-client-factory/ 

Avatar

Administrator

@ElvisRo Did you find the suggestions helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!



Kautuk Sahni