Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Sling GET servlet

rish_roy
Level 1
Level 1

Hi All,

Can someone share the example of How to write the REST API GET method in AEM where data can be shared in the form of  JSON when any client make the rest api call .

thanks

1 Accepted Solution
piotrkot
Correct answer by
Level 1
Level 1
0 Replies
kautuk_sahni
Community Manager
Community Manager

Hi 

To write REST Get/post method, you need to create a JAVA Sling Servlet.

 Link:-https://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html

// Here is the example for this.

Package :- https://helpx.adobe.com/experience-manager/using/custom-sling-servlets/_jcr_content/main-pars/downlo...

Here we are submitting data to POST method via AJAX call:-

$.ajax({
         type: 'POST',   
         url:'/bin/mySearchServlet',
         data:'id='+ claimId+'&firstName='+ myFirst+'&lastName='+ myLast+'&address='+ address+'&cat='+ cat+'&state='+ state+'&details='+ details+'&date='+ date+'&city='+ city,
         success: function(msg){
           alert(msg); //display the data returned by the servlet
         }
     });

Here URL is the path for request.

 

If you want to integrate or invoke 3rd party restful web service, see this

Link:- https://helpx.adobe.com/experience-manager/using/restful-services.html

// Creating Adobe Experience Manager bundles that invoke third party Restful web services

I hope this would help you.

~kautuk

rish_roy
Level 1
Level 1

Hi kautuk,

Can you share the example of custom JAVA Sling Servlet using the GET method where the data is entered by the author using the classic dialog is return in json format when the rest api get method request is made.

thanks

piotrkot
Correct answer by
Level 1
Level 1