Getting started
Guidewire distributes the REST API client as a ZIP file that contains a Gradle project. You can download the REST API client rest-api-client-project-version.zip file from the Guidewire Community website. The project contains the distribution for both, the REST API client plugin and REST API client library. The following table lists all project folders, the project configuration files, and explains their purpose.
| Project Folder | Description |
|---|---|
| /build | Contains the generated REST API client along with all dependent libraries. You deploy this ZIP to the IS application. |
| /build-script-libs | The libraries that Gradle uses |
| /client-libs | The REST API client library client-version.jar along with a POM file that can be used to build the project with Maven. |
| /compile-libs | Use the libraries in this folder for testing. |
| /endpoint | Contains the OpenApi code generator plugin. This folder appears when you open the project in IntelliJ or run gradle wrap. |
| /gradle | Gradle Wrapper executable JAR and its properties file |
| /libs | The dependent libraries that REST API client uses |
| build.gradle | Gradle build script for configuring the current project |
| gradle.properties | Contains the properties for the build script |
| gradlew | Gradle Wrapper script for Unix-based systems. This file downloads the proper version of Gradle if it is not present in the environment. This folder appears when you open the project in IntelliJ or run gradle wrap. |
| gradlew.bat | Gradle Wrapper script for Windows. This file downloads the proper version of Gradle if it is not present in the environment. This file appears when you open the project in IntelliJ or run gradle wrap. |
| README.md | The project documentation |
| settings.gradle | Gradle settings script for configuring the Gradle build. Defines all included sub-modules. During initialization, Gradle reads the settings.gradle file to figure out which projects to include in a build. . |
The REST API client project is configured to use the PetStore https://petstore.swagger.io/ REST service to illustrate how to generate the REST API client with this service. Initially, you use this configuration to test the generated client in your IS application. Next, you modify the project settings to configure the OpenAPI-compliant service endpoints and generate your own client. To start using the code generation plugin you need to unzip the distribution zip file and open the Gradle project in your IDE. The instructions in this guide assume that you use IntelliJ.
Step1: Download the REST API client
To download the client, log in to Guidewire Community website and download the rest-api-client-project-version.zip file.
Step 2: Unzip the zip file to your environment
- Unzip the file to your local file system
- Import the Gradle project to IntelliJ, or the IDE that you use
Step 2: Update the project configuration
Update the following configuration files to configure your client:
- Open build.gradle file to update the following three parameters:
- gwRestGen_endpoint_package
Defines the generated client package name
- gwRestGen_endpoint_source
Defines the source for the endpoint. It can be a REST service endpoint OpenAPI spec URL or a local file path to the OpenAPI spec JSON file.
- gwRestGen_isInsuranceSuite
Defines the client deployment target. When the target is an InsuranceSuite application the build task packages the client along with the necessary libraries.
ext { gwRestGen_endpoint_package = "petstore" gwRestGen_endpoint_source = "https://petstore.swagger.io/v2/swagger.json" gwRestGen_isInsuranceSuite = "true" } - gwRestGen_endpoint_package
- Update settings.gradle to include the client package to the build. You can
configure multiple client packages, as shown in the following example. Respectively, you
must configure the endpoint parameters for each package in
build.gradle:
include 'claimcenter:v1' include 'policycenter:v1'
Step 3: Build the client
The project provides Gradle task that you use to build the client. For details, see REST API client plugin tasks. In this project the code generation plugin generates a client against the PetStore service. Since the endpoint source is defined as an OpenAPI spec URL, you execute the following commands:- Run the restDownload task to download the OpenAPI spec JSON file. To run a task
with the wrapper, use one of the following commands from a Terminal window:
- On Mac or Linux, run
./gradlew restDownload - On Windows:
gradlew restDownload
In IntelliJ, you can also run the
restDownloadtask from Gradle task window.Note: If you define the gwRestGen_endpoint_source as a relative path to a JSON file, therestDownloaddoes not appear in the available tasks. - On Mac or Linux, run
- Generate the client. To run a task with the wrapper, use one of the following commands
from a Terminal window:
- On Mac or Linux, run
./gradlew build - On Windows:
gradlew build
- On Mac or Linux, run
The build generates the client library <project>/endpoint/build/libs/gwgen.petstore-version.jar.
Step 4: Publish the generated client
To publish the client to InsuranceSuite application run the publish task. To run a task with the wrapper, use one of the following commands from a Terminal window:
- On Mac or Linux, run
./gradlew publish - On Windows:
gradlew publish
In IntelliJ, you can also run the publish task from Gradle task
window.
- The generated client <project>/endpoint/build/libs/gwgen.petstore-version.jar
- The REST API client library /client/libs/client-version.jar
- All libraries from /libs folder
Step 5: Deploy to InsuranceSuite application
- Stop the InsuranceSuite application
- Extract build/distribution/endpoints-version.zip to <IS>modules/configuration/plugins/shared/lib folder in an InsuranceSuite application installation
- Start the InsuranceSuite application
Step 6: Test the client in InsuranceSuite application
To test the client you create and run a test in Gosu Scratchpad in InsuranceSuite Studio. The test submits REST API requests to the PetStore service to get the store inventory and get information about the sold and available pets.
- Open InsuranceSuite Studio:
gwb studio - To open Gosu scratchpad, click Tools → Gosu Scratchpad
- In Gosu scratchpad, type the following
code:
uses gw.restclient.config.Config uses gw.restclient.util.StaticMapper uses gwgen.petstore.ApiClient uses gwgen.petstore.api.StoreApi uses gwgen.petstore.api.PetApi uses gwgen.petstore.model.Pet uses gwgen.petstore.model.Category uses gwgen.petstore.model.Pet.StatusEnum var mapper = StaticMapper.yaml() var config = Config.builder().basePath(ApiClient.BASE_PATH).build() var storeApi = config.buildAPI(StoreApi) var inv = storeApi.getInventory() inv.forEach( \ key, cnt -> print("${key} = ${cnt}")) var petApi = config.buildAPI(PetApi) var rtn = petApi.findPetsByStatus({ StatusEnum.AVAILABLE.toString(), StatusEnum.SOLD.toString() }) print(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(rtn)) - To run the code, click Run on the scratchpad navigation bar.
- The test completes and generate the similar to the following output. The output below
displays only part of the
response:
"C:\Program Files\Java\jdk1.8.0_152\bin\java.exe" -javaagent:C:\ClaimCenter\studio\sdk\lib\idea_rt.jar=50833:C:\ClaimCenter\studio\sdk\bin -Dfile.encoding=UTF-8 -classpath C:\Users\user1\AppData\Local\Temp\classpath7313323.jar gw.lang.Gosu "C:\Users\user1\AppData\Local\Temp\6dace4b4\Gosu Scratchpad.gsp" sold = 190 string = 292 pending = 182 availableTINFOILLLLLLLLLLLLLLLLLL....LLLLLLLLLLL = 1 available = 292 soldTINFOILLLLLLLLLLLLLLLLLL....LLLLLLLLLLL = 1 --- - id: 7777778888889957853 category: name: "string" name: "doggie" photoUrls: - "string" tags: - name: "string" status: "available" - id: 7777778888889957854 category: name: "string" name: "doggie" photoUrls: - "string" tags: - name: "string" status: "available" - id: 7777778888889957865 category: name: "string" name: "doggie" photoUrls: - "string" tags: - name: "string" status: "available" - id: 213124125 category: id: 12 name: "cats" name: "Garfield" photoUrls: [] status: "available" - id: 7777778888889957875 category: name: "string" name: "doggie" photoUrls: - "string" tags: - name: "string" status: "available" - id: 1234 category: name: "string" name: "casper" photoUrls: - "string" tags: - name: "string" status: "available" .... Process finished with exit code 0
