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

Best practice for creating APIs in AEM

TB3dock
Level 7
Level 7

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?  

 

1 Accepted Solution
KiranVedantam1992
Correct answer by
Community Advisor
Community Advisor
2 Replies
KiranVedantam1992
Correct answer by
Community Advisor
Community Advisor
Jörg_Hoh
Employee
Employee

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