Bryan Williams - ICF Interactive
Many sites need to expose their AEM repository content through a flexible remote API whether it be for consumption by mobile apps, third parties, etc. This presentation will walk through setting up a custom, extensible, secure and testable API utilizing various open source tools that are at your disposal.
5. What do I mean by Content API?
• Read only
• Controlled
• Possibly public but not necessarily
• Usually an afterthought
• Disclaimer: Not production code
6.
7. Why not use something else?
• Not saying you shouldn’t
• Security : Control of who can access your
data
• Encapsulation : Granular control of what data
is exposed
• Simplicity : The easier for the consumer to
understand the better
• Conformity : Maybe you need to conform to a
particular spec
• Aggregation : Some data might be coming
from outside the repository
• Versioning : Backwards compatibility
9. What are Bedrock, CQCP and Prosper?
• Bedrock : Open source library that contains common
utilities, decorators, abstract classes, tag libraries and
Javascript modules for bootstrapping and simplifying
AEM projects
• CQ Component (Maven) Plugin : Generates
many of the artifacts necessary for the creation of a CQ
component based on the information provided by the
component’s backing Java class
• Prosper : An integration testing library for AEM
projects using Spock (a Groovy-based testing
framework)
10. Sling Models
• Automates mapping of Sling objects such
as resources, request, etc. to POJOs
• Available out of the box in AEM 6
11. Why Jackson?
• Popular
• Able to produce JSON or XML
• Lots of features
• We were already using it
12. Groovy
• An object-oriented programming language
for the Java platform
• Dynamic in nature
• Reduced syntax
• Traits
14. Layers of a Content API
• Component Models : Referring to both page and
content components and their corresponding backing
beans
• Servlet : Takes the request and calls the appropriate
service based on selectors
• Service : Responsible for getting the appropriate data
and possibly caching
• Query Builder : API for making queries to the
repository
• Filters : Last minute cleanup of outgoing data
(externalize URLs, etc.)
15. Non-Page Components
• Children of stories
• Returned in getBody() of Story model
• Custom and OOTB components must
have backing bean
• Models identified by path convention
circuit2015/groovy/components/page/stories/article
=
com.bryanw.conferences.circuit2015.groovy.components.page.stories.article.Article
26. Content API Servlet
• Accepts page paths only
• Accepts XML/JSON extension
• Accepts “story” and “stories” selector
• Constructs search parameters
• Passes current path and search
parameters on to service
50. Testing with Prosper
• Integration testing using Spock/Groovy
• Specifically for AEM testing
• Builders for Nodes/Pages
• Uses Sling Mocks
51. Publish vs Author
• May want internal apps to access author
• replicatedDate is not what it seems
52. Conclusions
• Bedrock
– https://github.com/Citytechinc/bedrock
– Provided us with useful classes, annotations and model injectors
• CQ Component (Maven) Plugin
– https://github.com/Citytechinc/cq-component-maven-plugin
– Allowed us to create dialogs without writing a single XML file
• Sling Models
– https://sling.apache.org/documentation/bundles/models.html
– Wired up our backing beans for us
• Jackson
– https://github.com/FasterXML/jackson
– Let us define the details of bean to JSON/XML conversion
• Prosper
– https://github.com/Citytechinc/prosper
– Simplified tests
• Groovy
– http://www.groovy-lang.org/
– Less code