Mastering Producing Liferay Headless APIs

Extending No-Code APIs with Object Actions

While basic CRUD operations are sufficient for core data management, modern applications often require executing intricate business logic. This is especially true for day-to-day operations where automated processes and real-time updates are critical. This article explores how to extend objects with APIs that execute custom business logic.

Leveraging Object Actions

Object actions in Liferay empower you to automate and streamline operations within your application. By defining triggers, conditions, and actions, you can implement custom business logic that responds to user interactions or system events.

By defining triggers, conditions, and actions, you can implement custom business logic that responds to user interactions or system events.

These elements determine the action's behavior and when it executes. Together, they enable you to tailor the object's behavior to your specific business requirements. For extending object APIs, the trigger is especially significant. An action trigger defines the event that initiates the action. Triggers can be automatic or standalone.

Automatic Triggers

Automatic triggers execute actions in response to an object entry event (e.g., when an entry is added, updated, or deleted). Here are some example use cases:

  • Data Synchronization: Automatically synchronize records with external systems when an entry is created or modified.
  • Process Automation: Initiate workflows, notifications, or other automation sequences based on object changes.
  • Business Rule Enforcement: Modify related object entries, enforce complex validations, or conditionally reject operations.

This event-driven approach offers key advantages. For instance, Liferay can push changes to external systems, eliminating the need for those system to constantly poll Liferay for updates. These processes are frequently used to automatically log job execution data when new jobs are added, send requests to external systems when jobs are completed, and enforce cleanup policies removing related event records when jobs are deleted.

Standlone Triggers

By contrast, when you select a standalone trigger, Liferay generates two API endpoints for executing the action manually or programmatically. You can call these endpoints at any time, independent of object entry events.

When you select a standalone trigger, Liferay generates two API endpoints for executing the action manually or programmatically.

Here are some example use cases:

  • On-Demand Calculations: Perform specific calculations, such as price adjustments or eligibility checks, upon request.
  • Manual Data Validation: Trigger complex data validation routines outside of standard entry creation or updates.
  • Custom Report Generation: Generate tailored reports or data exports based on user or system requests.
  • External System Interactions: Initiate immediate communication with external systems, such as sending data, or triggering specific processes.

Standalone triggers are exceptionally versatile. For instance, you might use them to generate invoices, send data to an external system for analysis, or initiate complex data transformations. You could trigger these actions manually via a UI button or programmatically using the action's APIs.

Conclusion

Object actions provide a rapid, code-light approach to extending default APIs and incorporating business logic directly into API calls. Automatic actions facilitate data synchronization, process automation, and business rule enforcement in response to object entry events. Standalone actions provide on-demand execution via custom API endpoints. Together, these capabilities enable the creation of intelligent, responsive applications that extend Liferay's headless API capabilities.

Next, you'll implement Clarity's distributor validation object, automatically generating no-code APIs in the process.

  • Leveraging Object Actions

  • Conclusion

Capabilities

Product

Education

Contact Us

Connect

Powered by Liferay
© 2024 Liferay Inc. All Rights Reserved • Privacy Policy