How to programmatically GET and POST the JCR nodes as rest/web API | Community
Skip to main content
Level 2
September 30, 2022
Solved

How to programmatically GET and POST the JCR nodes as rest/web API

  • September 30, 2022
  • 3 replies
  • 1594 views

Exploring the ways to access the node properties and update them as as independent solution like Rest or Web API which can be consumed/utilized by any third party system based upon requirement. 

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

For the fetching part I would normally recommend to use Sling Models and the Sling Model exporter, because it allows you do refine your JSON very explicitly.

 

If you just want to a generic POST and GET approach and write/read resources, you can use the Sling DefaultGetServlet [1] and DefaultPostServlet [2].

 

 

[1] https://sling.apache.org/documentation/bundles/rendering-content-default-get-servlets.html

[2] https://sling.apache.org/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.html

 

3 replies

Jagadeesh_Prakash
Community Advisor
Community Advisor
September 30, 2022

@sunilbansal17 

If you want to access the node properties under /content/ below are some of the properties. Please refer to below URL if this is helpful

 

https://experienceleague.adobe.com/docs/experience-manager-65/developing/components/json-exporter.html?lang=en

 

Chandra_Hire
Level 4
October 3, 2022

Hi @sunilbansal17 ,

 

AEM supports OOTB GET APIs to expose content as content service (as mentioned in @jagadeesh_prakash comment below).  For POST and other type of APIs, need to create an OSGi service layer (mostly Sling Servlet) which will accept the request and process accordingly using external APIs like Apache Sling, Oak and JCR APIs which deals with content repository. (Please find information about these API in API Guides | Adobe Experience Manager). 

Note: It needs to be taken care of maintaining all the AEM instance in sync when content gets posted/deleted to any of the instance in the farm.

 

Hope this helps.

joerghoh
Adobe Employee
joerghohAdobe EmployeeAccepted solution
Adobe Employee
October 3, 2022

For the fetching part I would normally recommend to use Sling Models and the Sling Model exporter, because it allows you do refine your JSON very explicitly.

 

If you just want to a generic POST and GET approach and write/read resources, you can use the Sling DefaultGetServlet [1] and DefaultPostServlet [2].

 

 

[1] https://sling.apache.org/documentation/bundles/rendering-content-default-get-servlets.html

[2] https://sling.apache.org/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.html

 

October 13, 2022

Thanks Jorg for your response.

Looks like For POST request, sling servlet is the only way which can be accessed as api request/response mode.