Introduction
API Builder at Liferay is useful for building the RESTful APIs for headless applications. It seamlessly fits into the Liferay tool environment and offers the developers the capacity for API building. This blog will explain the Liferay API Builder entirely through its implementation of creating a car API that supports GET and POST methods.
Prerequisites
- Liferay DXP 2023.Q4+/Portal 7.4 GA102+
- Basic knowledge of Liferay
What is API Builder?
API Builder is a feature in Liferay designed to enable developers to:
- REST APIs are defined through user-friendly interfaces.
- Create endpoints filled with a base amount of code automatically.
- Offer to create, read, and update capabilities.
- Specific requirements for a business can be incorporated in the generated APIs.
One of its strengths is that it enhances the process of API creation and decreases the amount of hand coding necessary.
Enable API Builder Beta Flag
- Log in to your Liferay instance as an administrator.
- Go to Control Panel > Instance Settings > Feature Flags > Beta.
- Enable API Builder Flag.

Let’s take an example of Car API
Consumers can manage car data and inventoried vehicles and clearly understand the structure of the Car API. The API provides a connection between car details, the manufacturers, and prospective clients with the car’s information updated in real-time.
- GET : Retrieve a list of cars with their details.
- POST : Add a new car to the collection.
Step 1 : Set Up the API Builder
- Log in to your Liferay instance as an administrator.
- Go to Control Panel > Object > API Builder.
- Click on + to create a new API.

Step 2 : Define/Add the Car Object
- Add the following fields to the Car object:
- carManufacturer (String): Car maker (e.g., Toyota, Ford).
- manufacturingYear (Integer): The manufacturing year of the car.
- model (String): model number of the car (e.g., Corolla, Mustang).
- name (String): Name of the car (e.g., BMW)
- price (Decimal): Price of the car.
Step 3 : Define Schema
- Select the following fields:
- Name
- Description
- Object

- Select properties from object fields from the right panel.

Step 4 : Create GET Endpoint
- Select the endpoints for the Car entity:
- /get-cars: Get the list/collection of cars.

- Select configurations:
- Response Body Schema : CarDetail.
- Filters : If you pass any filter. (e.g., price eq ‘4000000’, You can create your own filters from here filter, sort, and search)
- Sorting : add a sort.

Step 5 : Create POST Endpoint
- Select the endpoints for the Car entity:
- /add-car : Add a new car.

- Select configurations:
- Request Body Schema : CarDetail
- Response Body Schema : CarDetail

Step 6 : Publish and Test the API
- You can test the API using tools like Postman, cURL, or Liferay’s built-in API Explorer(e.g, localhost:8080/o/api)
- Click on Rest Applications
- Go to c/car


Advantages of the Liferay API Builder
- Rapid Development : The tool helps to shorten the API development time by performing some of the API generation steps mechanically.
- Seamless Integration : Liferay APIs are easy to work with in their ecosystem.
- Scalability : Integrated facilities for scaling and the possibility of customization.
- Standardization : Pursues compliance with RESTful design patterns.
Conclusion
The Liferay API Builder is a low-code/no-code solution implemented for both developers and non-developers with the purpose of creating fresh, optimized RESTful API flows. It makes API design easier by having an easy-to-understand, friendly interface while still enabling the generation of CRUD operations. This makes it a perfect solution for everyone who wants an easy-to-utilize fancy scheduler with some level of flexibility.