What is the best approach to expose an API hosted on AEM as a REST API | Community
Skip to main content
Level 3
January 17, 2023
Solved

What is the best approach to expose an API hosted on AEM as a REST API

  • January 17, 2023
  • 3 replies
  • 1291 views

Env. - AEM-Forms 6.5v, on-premise setup.

 

We want to use OutputService/ FormsService/ AssemblerService to generate a PDF using XML payload (coming from 3rd party system) and XDP template stored in AEM repository. So what is the best approach to expose this API as REST which will be hosted on AEM-Forms.

 

3rd party system will be calling AEM-Forms API with a xml payload to generate the PDF. Some of the searches suggested following [1], do let us know your opinions:

- A a path based Sling servlet with POST method

- an OSGi service  

 

[1] https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/exposing-rest-web-services-in-aem/m-p/211956

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

Pulkit_Jain_
Adobe Employee
Adobe Employee
January 17, 2023

@hrai 

As you know, sling servlet is one of the options to expose functionality in a RESTful way. More details about the related method for each service are here[0], along with the javadocs.

You can review the reference implementation for the Assembler service[1] and Forms/Output service [2] and adapt these as per your use case.

 

[0] - https://experienceleague.adobe.com/docs/experience-manager-65/forms/install-aem-forms/osgi-installation/install-configure-document-services.html?lang=en

[1] - https://experienceleague.adobe.com/docs/experience-manager-learn/forms/document-services/using-assembler-service-in-aem-forms.html?lang=en 

[2] - https://experienceleague.adobe.com/docs/experience-manager-learn/forms/document-services/output-and-forms-services-article-develop.html?lang=en

 

 

Monendra_Singh
Level 3
January 17, 2023

The best approach for exposing the OutputService/FormsService/AssemblerService as a REST API hosted on AEM-Forms would likely be to create a custom Sling Servlet. The servlet should be configured to handle requests using the POST method, and should be able to process the XML payload from the 3rd party system and use it to generate a PDF using the XDP template stored in the AEM repository.

Alternatively, you can use an OSGi service with the same functionality, it will have the same functionality as the Sling Servlet. This will make the service available to other OSGi components in the system and can be easily configured and managed through the OSGi framework.

In either case, it is important to ensure that the API is properly secured and that only authorized 3rd party systems are able to access it.

You can refer to this article in case you want to see which servlet approach suits.

  1. Mastering Servlet Creation in AEM: 4 Approaches and Best Practices - https://medium.com/@monendra80/mastering-servlet-creation-in-aem-4-approaches-and-best-practices-95cf8b5eb3f6
  2. Securing Servlets from Cyber Attacks: Code Examples, Best Practices and Prevention Techniques - https://medium.com/@monendra80/the-ultimate-guide-to-securing-servlets-in-aem-code-examples-best-practices-and-prevention-33bdb7359b51

 

 

hraiAuthor
Level 3
January 17, 2023

>>  The best approach for exposing the OutputService/FormsService/AssemblerService as a REST API hosted on AEM-Forms would likely be to create a custom Sling Servlet. The servlet should be configured to handle requests using the POST method, and should be able to process the XML payload from the 3rd party system and use it to generate a PDF using the XDP template stored in the AEM repository.

 

Okay, I assume then path based sling servlet can be used here, which will be exposed as REST API (already tested with Postman) works fine.

@8220494(service = { Servlet.class }, property = { SLING_SERVLET_METHODS + "=POST", SLING_SERVLET_EXTENSIONS + "=json", SLING_SERVLET_PATHS + "=/bin/generatePDFService" }) public class GeneratePDFService extends SlingAllMethodsServlet { ---- Document doc = outputService.generatePDFOutput(xdpDoc, xmlDoc, outputOptions); --- }

workflowuserAdobe EmployeeAccepted solution
Adobe Employee
January 17, 2023