Expand my Community achievements bar.

SOLVED

How to deal with third party integration in AEM 6.5

Avatar

Level 3

Hi All, 

Hope you all are doing well & safe. 

 

Need one help regarding any third party API integration in AEM 6.5 and to display it's data using HTL.

What approach we have to follow to make it highly scalable and efficient.

Kindly guide. 

Thanks in advance, 

Regards, 

Pavan 

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @phampi 

To integrate third-party there is 2 approach. 1) Server-Side Rendering & 2) Client-Side Rendering

Server-Side Rendering Approach:

  1. Create an OSGi Service Layer:

    • Develop an OSGi service responsible for interacting with the third-party API. This service should handle making API requests and processing responses.
    • Define methods within the service to perform various operations required by the integration.
  2. Expose Operations:

    • Expose the necessary operations from the third-party API through methods in the OSGi service. These methods should encapsulate the logic for interacting with the API endpoints.
  3. Sling Models for Server-Side Components:

    • Create Sling Models for AEM components that will display data fetched from the third-party API.
    • Inject the OSGi service into these Sling Models using the @osgiservice annotation.
    • Implement getter methods in the Sling Models to retrieve the data from the OSGi service and expose it to HTL templates.
  4. HTL Templates:

    • Develop HTL templates to render the data fetched from the third-party API.
    • Use data-sly-use to invoke the Sling Models and access the exposed data through getter methods.
    • Use HTL's directives like data-sly-list or data-sly-repeat to iterate over collections of data and generate HTML markup dynamically.

Client-Side Rendering Approach:

  1. Create an OSGi Service Layer:

    • Develop an OSGi service responsible for interacting with the third-party API, similar to the server-side approach.
  2. Expose Operations:

    • Expose the necessary operations from the third-party API through methods in the OSGi service, as before.
  3. Sling Servlet for Data Retrieval:

    • Create a Sling Servlet to handle requests for fetching data from the third-party API.
    • Inject the OSGi service into the Servlet using the @Reference annotation to fetch data from the API.
  4. Client-Side Integration:

    • Develop client-side JavaScript code to make AJAX requests to the URL endpoint exposed by the Sling Servlet.
    • Upon receiving the API response, dynamically render the data on the client-side using JavaScript frameworks like React, Vue.js, or Angular.
    • Implement error handling and graceful degradation mechanisms to handle scenarios where API requests fail or encounter errors.
  5. Integration with AEM Components (Optional):

    • Optionally, you can integrate the client-side rendering with AEM components by embedding JavaScript code within AEM components.
    • Ensure that the client-side rendering integrates seamlessly with AEM's component lifecycle and authoring experience.

 

By following these separate approaches, you can integrate third-party APIs into AEM using both server-side rendering and client-side rendering techniques, catering to different use cases and requirements.

In both cases there are some pros & cons as well.

Server-Side Rendering (SSR):

  • Best for SEO, initial page load performance, and content-heavy pages.
  • Ideal for static content or less interactive pages.
  • Seamless integration with AEM's authoring environment.
  • Faster time-to-content delivery.

Client-Side Rendering (CSR):

  • Suited for highly interactive user interfaces and SPAs.
  • Reduces server load and provides smoother user experiences.
  • Allows for decoupled frontend and backend architectures.
  • Enables personalization and real-time updates.

 

Asif Chowdhury

View solution in original post

3 Replies

Avatar

Level 6

Hi @phampi 
So third party API integrations I am assuming you want to make from server side and then display data using component HTL/Sightly.
This depends if you want to show data dynamically on the website i.e. load data on clientside for rendering ;; Or if you want to load HTL at server side and then serve it to client server as cached response.
1. In both the case , standard approach says create a service layer for the 3rd Party API ( OSGI service) 
Here is a reference for the same https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/how-to-call-3rd-part-rest-...

Using this OSGI service you can expose the operations you want to perform from the API using overridden methods (as you would in an osgi service)

2. Now in case you want to load the response from the API using sightly in the component , you can use sling model for the component to refer the osgi service using @osgiservice annotation and then expose the processed content using model getter methods into HTL.
3.  Another case is you want to load data dynamically on clientside using frontend , then you can create a sling servlet and then use osgi service reference using @Reference annotation to fetch data from the API and expose over the network via url.

 

Another reference that might help https://sourcedcode.com/blog/aem/scenario-building-aem-components-with-3rd-party-integrations-the-ri...


 

Avatar

Correct answer by
Community Advisor

Hi @phampi 

To integrate third-party there is 2 approach. 1) Server-Side Rendering & 2) Client-Side Rendering

Server-Side Rendering Approach:

  1. Create an OSGi Service Layer:

    • Develop an OSGi service responsible for interacting with the third-party API. This service should handle making API requests and processing responses.
    • Define methods within the service to perform various operations required by the integration.
  2. Expose Operations:

    • Expose the necessary operations from the third-party API through methods in the OSGi service. These methods should encapsulate the logic for interacting with the API endpoints.
  3. Sling Models for Server-Side Components:

    • Create Sling Models for AEM components that will display data fetched from the third-party API.
    • Inject the OSGi service into these Sling Models using the @osgiservice annotation.
    • Implement getter methods in the Sling Models to retrieve the data from the OSGi service and expose it to HTL templates.
  4. HTL Templates:

    • Develop HTL templates to render the data fetched from the third-party API.
    • Use data-sly-use to invoke the Sling Models and access the exposed data through getter methods.
    • Use HTL's directives like data-sly-list or data-sly-repeat to iterate over collections of data and generate HTML markup dynamically.

Client-Side Rendering Approach:

  1. Create an OSGi Service Layer:

    • Develop an OSGi service responsible for interacting with the third-party API, similar to the server-side approach.
  2. Expose Operations:

    • Expose the necessary operations from the third-party API through methods in the OSGi service, as before.
  3. Sling Servlet for Data Retrieval:

    • Create a Sling Servlet to handle requests for fetching data from the third-party API.
    • Inject the OSGi service into the Servlet using the @Reference annotation to fetch data from the API.
  4. Client-Side Integration:

    • Develop client-side JavaScript code to make AJAX requests to the URL endpoint exposed by the Sling Servlet.
    • Upon receiving the API response, dynamically render the data on the client-side using JavaScript frameworks like React, Vue.js, or Angular.
    • Implement error handling and graceful degradation mechanisms to handle scenarios where API requests fail or encounter errors.
  5. Integration with AEM Components (Optional):

    • Optionally, you can integrate the client-side rendering with AEM components by embedding JavaScript code within AEM components.
    • Ensure that the client-side rendering integrates seamlessly with AEM's component lifecycle and authoring experience.

 

By following these separate approaches, you can integrate third-party APIs into AEM using both server-side rendering and client-side rendering techniques, catering to different use cases and requirements.

In both cases there are some pros & cons as well.

Server-Side Rendering (SSR):

  • Best for SEO, initial page load performance, and content-heavy pages.
  • Ideal for static content or less interactive pages.
  • Seamless integration with AEM's authoring environment.
  • Faster time-to-content delivery.

Client-Side Rendering (CSR):

  • Suited for highly interactive user interfaces and SPAs.
  • Reduces server load and provides smoother user experiences.
  • Allows for decoupled frontend and backend architectures.
  • Enables personalization and real-time updates.

 

Asif Chowdhury

Avatar

Level 3

Hi @AsifChowdhury , 

Thanks for the reply, could you pls share some links.

Regards, 

Pavan