Understanding Liferay's Headless APIs

APIs facilitate communication between systems and applications. They give you pre-built classes, interfaces, and methods for sending requests and receiving responses. An API call typically includes four primary components:

  • URL: The address of the API endpoint that is used to send requests for specific functions and data.

  • HTTP Methods: The actions to perform on the resource at the URL (e.g., GET, POST, PUT, DELETE).

  • Headers: Extra metadata included in the request to identify and parse its content.

  • Payload: The actual data being sent with the request, if any. For example, a new user API request would include a payload containing the user’s information.

An API call sends a request. The server processes it and returns a response, which can include the requested resources, error details, or confirmation of the action.

APIs give you pre-built classes, interfaces, and methods for sending requests and receiving responses.

With their decoupled architecture, headless APIs enable flexible content delivery across platforms, while allowing developers to choose their preferred tools. Other benefits include simplified development and enhanced security through OAuth2.

Liferay’s Headless APIs

Liferay provides an extensive list of out-of-the-box APIs for platform administration and content consumption, in two categories:

Administrative APIs manage users, accounts, organizations, commerce products, and more.

Delivery APIs allow you to supply web content, blogs, orders, and other assets to external applications.

With these APIs, you can execute most actions available via the standard Liferay UI, creating consistent and connected experiences across systems.

Examples of leveraging Liferay’s headless APIs include

  • Migrating data from legacy systems.

  • Populating custom web or mobile applications.

  • Building custom client extensions to interact with or extend Liferay DXP.

  • Creating automated processes such as batch user uploads or approval workflows.

  • Integrating AI models for advanced content analysis and generation.

Liferay’s sample API tutorials offer practical guidance for addressing these common use cases with headless APIs. See Headless APIs for more information.

REST and GraphQL Support

Liferay supports both REST and GraphQL endpoints for its headless APIs, providing flexibility in interacting with the platform.

  • REST APIs: Fully OpenAPI-compliant, Liferay's REST APIs follow RESTful architecture principles, offering multiple HTTP methods to interact with resources and returning a fixed set of data per endpoint. REST APIs are well-suited for straightforward CRUD operations, handling large data sets, and integrating Liferay's APIs into workflows using third-party tools.

  • GraphQL APIs: GraphQL APIs offer an alternative approach, enabling fetching and modifying data in a single, flexible query. This ability to select specific fields can improve efficiency through reduced payload sizes, although this flexibility may add additional complexity. GraphQL APIs are advantageous for situations where data requirements can change frequently or in applications where bandwidth is a concern.

To choose between REST and GraphQL, it’s important to consider feature availability, flexibility, project needs, and your own familiarity with each technology.

Conclusion

Liferay's extensive headless APIs offer a powerful framework for modern application development. Whether through established REST standards or flexible GraphQL queries, you can securely and efficiently work with Liferay’s data using its headless APIs.

Next, you’ll learn about fetching and rendering data with Liferay headless APIs.

loading-knowledge-label