Skip to content

Liferay REST Builder

Liferay REST Builder is a powerful tool that simplifies the creation of JAX-RS-based REST APIs in Liferay DXP/Portal. It generates DTOs (Data Transfer Objects), Resource classes, and OpenAPI documentation automatically, reducing boilerplate code.

This guide covers:

  1. Setting up REST Builder with Blade CLI
  2. Generating REST Modules
  3. Customizing Generated APIs
  4. Building & Deploying
  5. Testing REST APIs

  • Liferay DXP/Portal 7.4+
  • Liferay Workspace (with Blade CLI installed)
  • Java 11+

Installing Blade CLI

Terminal window
blade version

Use Blade CLI to scaffold a REST module:

Terminal window
blade create -t rest-builder -p com.example -c MyRestApi my-rest-api

This creates:

  • A JAX-RS resource (MyRestApiResource)
  • A DTO (MyRestApiDTO)
  • OpenAPI YAML (openapi.yaml)
graph TD
    A[my-rest-api] --> B[src/main/java]
    B --> C[com/example/MyRestApiResource.java]
    B --> D[com/example/dto/MyRestApiDTO.java]
    A --> E[src/main/resources]
    E --> F[openapi.yaml]

Define your API schema:

openapi: 3.0.1
info:
title: My REST API
version: v1.0
paths:
/my-rest-api:
get:
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/MyRestApiDTO"
components:
schemas:
MyRestApiDTO:
type: object
properties:
id:
type: string
name:
type: string
@Path("/v1.0/my-rest-api")
@Produces("application/json")
@Consumes("application/json")
public class MyRestApiResource {
@GET
public MyRestApiDTO getMyRestApi() {
return new MyRestApiDTO("1", "Example REST API");
}
@POST
public MyRestApiDTO createMyRestApi(MyRestApiDTO myRestApiDTO) {
return myRestApiDTO;
}
}
public class MyRestApiDTO {
private String id;
private String name;
// Getters & Setters
// Constructor
}

Terminal window
cd my-rest-api
./gradlew build
Terminal window
blade deploy

Check in Liferay Control Panel → Gogo Shell:

Terminal window
lb | grep my-rest-api

Terminal window
curl -X GET "http://localhost:8080/o/api/my-rest-api/v1.0/my-rest-api" -u test@liferay.com:test
  1. GET Request:
    http://localhost:8080/o/api/my-rest-api/v1.0/my-rest-api
    (Use Basic Auth with Liferay credentials)

  2. POST Request:

    {
    "id": "2",
    "name": "New REST API"
    }

@GET
public Page<MyRestApiDTO> getMyRestApiPage(
@Context Pagination pagination,
@Context Sort[] sorts
) {
// Fetch data with pagination
return Page.of(items, pagination, totalCount);
}
@GET
public MyRestApiDTO getMyRestApi(@Context User user) {
if (!PermissionChecker.contains(user.getRoles(), "VIEW")) {
throw new ForbiddenException();
}
return new MyRestApiDTO("1", "Example REST API");
}

REST Builder auto-generates OpenAPI docs:

  • Access at:
    http://localhost:8080/o/api?endpoint=http://localhost:8080/o/my-rest-api

Modify openapi.yaml:

paths:
/my-rest-api:
get:
summary: "Get My REST API"
description: "Returns a sample REST API response"

IssueSolution
404 Not FoundCheck if module is deployed (lb in Gogo Shell)
403 ForbiddenEnsure proper permissions in resource-actions
DTO not serializingEnsure @JsonSerialize annotations are used

Liferay REST Builder accelerates REST API development by: ✅ Generating boilerplate code
Supporting OpenAPI docs
Integrating with Liferay security

Use Blade CLI for quick scaffolding and Gradle for building.

  • Learn Liferay Headless APIs
  • Check Liferay REST Builder docs: