Liferay REST Patterns
Liferay REST modules are OSGi-based components that allow developers to create custom RESTful endpoints within the Liferay platform. These modules follow JAX-RS standards while integrating seamlessly with Liferay’s security and dependency injection systems.
graph TD
A[REST Module] --> B[OSGi Component]
A --> C[JAX-RS Implementation]
A --> D[Liferay Integration]
D --> E[Security]
D --> F[Service Builder]
D --> G[DTOs]
Types of REST Modules in Liferay
Section titled “Types of REST Modules in Liferay”1. Basic Resource Modules
Section titled “1. Basic Resource Modules”The simplest form of REST modules that expose standard CRUD operations.
classDiagram
class BasicResourceModule {
+@Path("/basic")
+@GET getItems()
+@POST createItem()
+@PUT updateItem()
+@DELETE removeItem()
}
2. Headless Delivery Modules
Section titled “2. Headless Delivery Modules”Extensions of Liferay’s headless delivery system for custom content types.
graph LR
H[Headless Delivery Module] --> A[Content]
H --> B[Documents]
H --> C[Custom Types]
H --> D[Structured Content]
3. Admin REST Modules
Section titled “3. Admin REST Modules”For administrative operations that require elevated permissions.
pie
title Admin Module Endpoints
"User Management" : 40
"Role Management" : 30
"Site Configuration" : 20
"System Settings" : 10
4. Composite Resource Modules
Section titled “4. Composite Resource Modules”Modules that aggregate multiple resources or services into single endpoints.
flowchart TB
subgraph CompositeModule
A[User Data] --> C[Endpoint]
B[Profile Data] --> C
D[Preferences] --> C
end
5. Proxy REST Modules
Section titled “5. Proxy REST Modules”Modules that act as intermediaries between Liferay and external systems.
sequenceDiagram
Client->>ProxyModule: Request
ProxyModule->>ExternalSystem: Forward
ExternalSystem->>ProxyModule: Response
ProxyModule->>Client: Return
REST Module Structure
Section titled “REST Module Structure”Core Components
Section titled “Core Components”graph TD
Module --> ApplicationClass
Module --> ResourceClasses
Module --> ExceptionMappers
Module --> Filters
ApplicationClass -->|Registers| ResourceClasses
ApplicationClass -->|Configures| Filters
Annotations Overview
Section titled “Annotations Overview”pie
title Common REST Module Annotations
"@Path" : 30
"@GET/POST/PUT/DELETE" : 25
"@Produces/@Consumes" : 20
"@Provider" : 15
"Liferay-specific" : 10
REST Module Implementation Patterns
Section titled “REST Module Implementation Patterns”1. Resource-Oriented Pattern
Section titled “1. Resource-Oriented Pattern”graph LR
Resources --> Users
Resources --> Documents
Resources --> Blogs
%% Each resource has full CRUD operations
Users -->|GET| ReadUser
Users -->|POST| CreateUser
Documents -->|PUT| UpdateDocument
Blogs -->|DELETE| RemoveBlog
2. Controller Pattern
Section titled “2. Controller Pattern”flowchart TB
Controller --> Service1
Controller --> Service2
Controller --> UnifiedResponse
Service1 -->|Business Logic| Database
Service2 -->|Business Logic| ExternalSystem
3. Microservice Gateway Pattern
Section titled “3. Microservice Gateway Pattern”graph TD
GatewayModule --> ServiceA
GatewayModule --> ServiceB
GatewayModule --> ServiceC
ServiceA -->|Data| MicroserviceA
ServiceB -->|Data| MicroserviceB
ServiceC -->|Data| MicroserviceC
Key Characteristics of Liferay REST Modules
Section titled “Key Characteristics of Liferay REST Modules”- OSGi-based: Deployed as modular components
- JAX-RS Compliant: Standard implementation
- Liferay Integrated: Security, DTOs, exceptions
- Versionable: Support for API versioning
- Documentable: OpenAPI/Swagger support
graph LR
Characteristics --> Scalability
Characteristics --> Security
Characteristics --> Maintainability
Characteristics --> StandardCompliance