Expand my Community achievements bar.

Retrieve selected properties of node(s) in JSON with REST

Avatar

Level 1

Hi,

I am developing a custom application where I need to get some selected properties of node(s) in JSON format with REST API.

Has anyone came across this kind of requirement?
Can it be achieved with default implementaion of Apace sling within AEM or do I need to write some custom REST API's ?

I also looked at an alternative "GraphQL" an open source project by facebook, this also provide some promising features to retrieve selected properties of node(s) but need a second opinion on this.

1 Reply

Avatar

Administrator

Hi 

Assuming you know the Query to extract what is required, 

Then to get JSON response from REST api can be achieved by Using Query Builder Debugger :- http://localhost:4502/libs/cq/search/content/querydebug.html

//  Once you write a query there and Search it, then in that case there you will get JSON Query builder Link.

Example:- 

Add Query :- type=nt:file
nodename=*.jar
orderby=@jcr:content/jcr:lastModified
orderby.sort=desc

 

Results

Number of hits: 212

Time: 2.99 seconds
/apps/myHTL/install/myHTL.core-1.0-SNAPSHOT.jar  (crxde,  html,  json)
/apps/msm/install/msmapi-bundle-1.0-SNAPSHOT.jar  (crxde,  html,  json)
/apps/queryBuilder/install/querybuilder-bundle-1.0-SNAPSHOT.jar  (crxde,  html,  json)
/apps/sightly/osgi-bundles/install/sightly-bundle-1.0-SNAPSHOT.jar  (crxde,  html,  json)
/apps/testmulti/install/testmulti.core-0.0.1-SNAPSHOT.jar  (crxde,  html,  json)
/apps/sightlymf/osgi-bundles/install/Touchmulti-bundle-1.0-SNAPSHOT.jar  (crxde,  html,  json)
/libs/cq/contentinsight/install/cq-content-insight-1.1.12.jar  (crxde,  html,  json)
/libs/cq/projects/install/com.adobe.cq.projects.core-0.1.60.jar  (crxde,  html,  json)
/libs/cq/projects/install/com.adobe.cq.projects.wcm.core-0.1.6.jar  (crxde,  html,  json)
/libs/cq/projects/install/com.adobe.cq.projects.api-0.1.2.jar  (crxde,  html,  json)

Json Link:- http://localhost:4502/bin/querybuilder.json?nodename=*.jar&orderby=%40jcr%3acontent%2fjcr%3alastModi...

 

To check if property starts with some string:- 

path=/content/dam
type=dam:Asset
property=jcr:content/metadata/dam:MIMEtype
property.value=image/%
property.operation=like
p.limit=-1

I hope this would help you.

Thanks and Regards

Kautuk Sahni



Kautuk Sahni