Expand my Community achievements bar.

SOLVED

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

Avatar

Level 2

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. 

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

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-po...

 

View solution in original post

4 Replies

Avatar

Community Advisor

@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.ht...

 

Avatar

Level 5

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.

Avatar

Correct answer by
Employee Advisor

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-po...

 

Avatar

Level 1

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.