Apache Sling is a web framework that maps HTTP request URLs directly to content nodes in a JCR repository. It is the foundation of Adobe Experience Manager (AEM), enabling developers to build content-driven applications efficiently. Beyond traditional page rendering, Sling is also a REST-first framework, allowing content to be exposed as JSON, XML, or HTML directly from the repository.
What is Apache Sling?
Apache Sling is an open-source web framework designed to expose content stored in a Java Content Repository (JCR) over HTTP. Unlike traditional web frameworks, Sling is content-first, meaning:
URLs directly map to content nodes in the JCR.
The framework dynamically resolves which scripts or servlets to execute based on the resource type and request parameters.
It integrates tightly with OSGi services for modular, reusable, and dynamic backend logic.
In short, Sling is the glue between HTTP requests, JCR content, and rendering logic, providing a content-driven, modular, and highly dynamic web framework.
Core Concepts of Apache Sling
Before diving deeper in the series, it’s important to understand Sling’s foundational concepts:
1. Resource
A Resource is Sling’s abstraction over a JCR node:
Encapsulates content and metadata.
Provides a uniform API to access properties.
Shields developers from the underlying JCR structure.
Example:
Resource resource = resourceResolver.getResource("/content/mysite/en/home");
String title = resource.getValueMap().get("jcr:title", String.class);
In AEM, every page, component, or asset is represented as a
Resource.
2. ResourceResolver
ResourceResolver is Sling’s access point to the repository:
Resolves paths or UUIDs to resources.
Handles user session and permissions.
Provides query and search APIs.
Think of it as your repository session manager for Sling.
3. Resource Type
Each resource in Sling has a sling:resourceType property:
Determines which script or servlet will render it.
Supports inheritance and override mechanisms.
Enables modular and reusable components.
Example:
sling:resourceType = "myproject/components/page"
Sling dynamically maps this resource type to the appropriate HTL or JSP script.
4. Request Resolution
Sling uses the request path, selectors, extension, and suffix to dynamically select the script or servlet:
Selectors: Custom request modifiers, e.g.,
.print.a4.htmlExtension: Output format, e.g.,
.html,.jsonSuffix: Extra path info for the request, e.g.,
/12345/details
This makes Sling extremely flexible for building RESTful endpoints, dynamic page rendering, and API-first applications.
5. Integration with OSGi
Sling relies heavily on OSGi services:
Back-end logic is decoupled and modular.
Components like Servlets, Filters, Models, and Services are managed by the OSGi container.
Dynamic wiring enables hot deployment and zero-downtime updates.
6. Content-First Approach
Unlike traditional frameworks that focus on routes or controllers:
Sling resolves requests based on content hierarchy in the repository.
Scripts are resolved dynamically via
ResourceType.Adding new pages or components often requires no code changes—just add content or scripts in the correct path.
Key Takeaways
Sling is content-driven, not URL-driven.
Every content node is a Resource, accessed via ResourceResolver.
sling:resourceTypedetermines how a resource is rendered.Selectors, extensions, and suffixes enable flexible request routing.
Integration with OSGi services ensures modular, maintainable backend logic.
Sling dynamically resolves scripts, servlets, and services, making AEM highly flexible.
What’s Next?
In the next post, we’ll dive into - Sling Resource Resolution: How Requests Map to Content.
Comments
Join the discussionNo comments yet. Be the first to comment.

