Follow these steps to use REST Builder to create a headless REST API for your app:
-
Create a project.
-
Install REST Builder. For instructions on this, see REST Builder Gradle Plugin.
-
Run
gradlew clean deploy
. Note that your Gradle wrapper may not be in your app’s project directory, so you may need to use..
to locate it (e.g.,../../../gradlew clean deploy
). -
Create the
*-api
and*-impl
projects with the usual files (build.gradle
,bnd.bnd
). Also create arest-config.yaml
with the author, paths, and packages. For example, here’s therest-config.yaml
for Liferay’sheadless-delivery
API:apiDir: "../headless-delivery-api/src/main/java" apiPackagePath: "com.liferay.headless.delivery" application: baseURI: "/headless-delivery" className: "HeadlessDeliveryApplication" name: "Liferay.Headless.Delivery" author: "Javier Gamarra" clientDir: "../headless-delivery-client/src/main/java" testDir: "../headless-delivery-test/src/testIntegration/java"
-
In your
*-impl
module’s root folder, write your OpenAPI profile in YAML. You can use the Swagger Editor to validate syntax and ensure compliance with the OpenAPI specification. -
In your
*-impl
module folder, rungradlew buildREST
(make sure you locate your Gradle wrapper as instructed in step two above). -
REST Builder generates the interfaces with the JAX-RS endpoints. It also generates a
*ResourceImpl
class where you must implement the business logic for each service. -
After implementing the business logic for each service, deploy your modules. Your APIs are then available at this URL:
http://[host]:[port]/o/[APPLICATION_CLASSNAME]/[OPEN_API_VERSION]/
You can also execute
jaxrs:check
in the OSGi console to see all the JAX-RS endpoints.