Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Sling GET servlet

Avatar

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

Avatar

Correct answer by
Level 1
4 Replies

Avatar

Administrator

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



Kautuk Sahni

Avatar

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

Avatar

Correct answer by
Level 1