Foundations of Liferay Headless APIs

Understanding Liferay’s Headless Framework

APIs establish a standardized communication pathway between systems. Developers can leverage pre-built classes, interfaces, and methods within APIs to facilitate interaction and service requests between applications. 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.

Following an API call, the server processes the request and returns a response. This response can include the requested resources, error details, or confirmation of the action.

An API call typically includes four primary components: URL, HTTP Methods, Headers, and Payload.

Headless APIs are valuable tools for modern application development. Their decoupled architecture enables flexible content delivery across various platforms and empowers developers to choose their preferred technologies. Other benefits include simplified development, enhanced security through OAuth2 adoption, and accelerated time-to-market.

Liferay’s Headless API Framework

Liferay provides an extensive list of out-of-the-box APIs for platform administration and content consumption. Administrator APIs enable you to manage users, accounts, organizations, commerce products, and more. Delivery APIs empower you to supply web content, blogs, orders, and other assets to external applications. This framework enables the execution of most actions available via the standard Liferay UI, so you can create 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 Sample API Tutorials 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, and project needs. For example, REST APIs are the preferred choice for object-based implementations. This is because the GraphQL APIs do not support retrieving or updating objects using ERCs, invoking object actions, using PATCH methods, or accessing relationship APIs. By contrast, REST fully supports these operations.

You can learn more about choosing between REST and GraphQL APIs in the Mastering Consuming Liferay’s Headless APIs (Coming Soon) and Mastering Producing Liferay’s Headless APIs (Coming Soon) courses.

Understanding Liferay API Versioning

Any time breaking changes are implemented for Liferay’s headless APIs, new versions of those APIs are released. This ensures continued functionality as Liferay is upgraded. For REST APIs, the version is part of the request URL (e.g., v1.0 in /o/headless-commerce-delivery-catalog/v1.0/channels/11/products). In GraphQL, you can specify the API version through versioned namespaces. See Consuming GraphQL APIs for more information.

Conclusion

Liferay's headless APIs offer a powerful framework for modern application development. Whether through established REST standards or flexible GraphQL queries, developers can effectively create seamless, interconnected experiences with Liferay's headless APIs.

Next, you’ll learn how to explore Liferay’s APIs using various tools.

  • Liferay’s Headless API Framework

  • REST and GraphQL Support

  • Understanding Liferay API Versioning

  • Conclusion

Capabilities

Product

Education

Contact Us

Connect

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