Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Sling API vs JCR API

Avatar

Level 4

AEM supports the use of both Sling APIs and JCR APIs. 

 

The docs mention "While the JCR is AEM’s content repository, its APIs are NOT the preferred method for interacting with the content. Instead prefer the AEM APIs (Page, Assets, Tag, and so on) or Sling Resource APIs as they provide better abstractions." 

 

Furthermore, "Broad use of JCR APIs’ Session and Node interfaces in an AEM application is code-smell. Ensure Sling APIs should be used instead."

 

Personally, I used the JCR API for creating nodes and properties in custom workflows.

And found it necessary to use the JCR API in the unit tests.

 

Did you personally come across any use cases where the JCR API is better than the sling API? 

And is it always a legitimate code smell? 

5 Replies

Avatar

Community Advisor

I can se only one use case when JCR api is better then Sling API

It is when you write Event on nodetype, which sling does not supports.

 

Always use Framework API first (AEM <-- Sling <--- JCR)



Arun Patidar

Avatar

Employee Advisor

Oh well, we are constantly trying to reduce the slack in Sling and make its performance on par with JCR; of course it's always a bit of overhead, but Sling offers some nice features which JCR cannot do; mostly because it's a fixed API we cannot extend anymore.