Best practice for creating APIs in AEM

Avatar

Avatar

TB3dock

Avatar

TB3dock

TB3dock

22-03-2021

In Java projects, one would usually use spring boot, and generate versioned apis from annotated controllers and models and use swagger to test/document.  APIs would include customer login, registration, edit details, get order history etc.  Some calls search and return content, e.g using sql2 and some will hit back ends behind aem.  They would use Json. 

 

while we could hand write servlets which manually unmarshal and marshal request and response objects, this would be like going back to the 80s.

 

Does aem have a recommended way to create versioned apis for the front end to consume, with built in documentation generation?

 

I saw there is a swagger aem project, but not sure how this would work with aem not being spring or mvc

 

i understand that aem uses sling, but I haven’t found a tutorial on how this might be used, and the sling servlet reference docs don’t seem to have a way to specify the actual type of the request and response other than as SlingHttpServletRequest and SlingHttpServletResponse, which require writing your own get param extraction and writing your own json out (vs something which takes a java object and constructs the json for you). I haven’t seen something like swagger for it?  

 

Answers (1)

Answers (1)

Avatar

Avatar

Jörg_Hoh

Employee

Total Posts

3.1K

Likes

1.0K

Correct Reply

1.1K

Avatar

Jörg_Hoh

Employee

Total Posts

3.1K

Likes

1.0K

Correct Reply

1.1K
Jörg_Hoh
Employee

25-03-2021

Unlike other frameworks, AEM is resource-based, and the resource defines the contract in the first place, but not the code. The most API-like thing, which comes close to the idea of other frameworks are Content-Fragments because there the structure and the content is clear. Also the SlingModel Exporter gives you the chance to control the details of the payload you get. So when you use AEM as a remote system (in a kind of headless way), these are the APIs you should look for.

 

Jörg