I am going to implement a REST API in AEM to integrate 3rd party applications.
I do not want to rely in the JCR repository hierarchy, because my internal hierarchy does not matter to the 3rd party applications. So, I do not want to map my Sling servlets to a resourceType (that would mean to specify the path to the resource, so using the JCR hierarchy).
So, I need to map the servlets to a path.
Following the REST API development best practices, I should use a path like ‘/api/v1/articles’ to implement operations like search and create new article (with GET and POST HTTP methods), and a path like ‘/api/v1/articles/<article_id>’ to implement operations like get details and modify a specific article (also with GET and POST HTTP methods).
My question is, is it possible to map Sling servlets to a paths like those, where the <article_id> is variable?
While JAX-RS connector can be integrated to use @PathParam syntax; taking dynamic parts of the request as suffix is a good option too. With suffix, the servlet request would be /api/v1/articles.json/<article_id> and then read the article id in the servlet with request.getRequestPathInfo().getSuffix()
yes it is doable but only with the help of query parameter for <article_id> or by doing some string manipulation to get the <article_id> to pass as selector to invoke the appropriate servlet.
With Jax-rs connector also you can not because the available library for the same is using very old version of some dependency, those are not compatible with the current version of aem. so you will have to build is fresh before using it. then again some request filter will be required to handle the authentication an all but again here also request suffix will not work.