How to programmatically GET and POST the JCR nodes as rest/web API | Community
Skip to main content
Level 2
Sep 30, 2022 11:09 AM UTC
Solved

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

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.
joerghoh
joerghohAccepted solution
Employee
Oct 3, 2022 5:58 PM UTC

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

 

4 replies

joerghoh
joerghohAccepted solution
Employee
Oct 3, 2022 5:58 PM UTC

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

 

Translate
New Participant
Oct 13, 2022 11:45 AM UTC

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.

Translate
Chandra_Hire
Level 4
Oct 3, 2022 9:32 AM UTC

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.

Translate
Jagadeesh_Prakash
New Participant
Sep 30, 2022 12:46 PM UTC

@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

 

Translate