[8.5.5.9 or later]

Generating a JAX-RS 2.0 client from a REST API definition file

You can generate a Java API for RESTful Web Services (JAX-RS) 2.0 client in a Java™ Platform, Enterprise Edition (Java EE) 7 web project. This JAX-RS 2.0 client is based on a REST API definition file that is named swagger.json.

About this task

Important: Applicable to Liberty

Procedure

  1. Open the Generate JAX-RS Client wizard by completing one of the following options:
    • Right-click a swagger.json file in your workspace and select RESTful Services > Generate JAX-RS Client.

      The tools display the Generate JAX-RS Client window.

    • Complete the following steps to open the Generate the JAX-RS Client wizard from the New Wizard window:
      1. From the Eclipse workbench, select File > New > Other....

        The tools display the New Wizard window.

      2. Select RESTful Services > Generate JAX-RS Client.
      3. Click Next.

        The tools display the Generate JAX-RS Client window.

  2. Enter the location of the swagger.json file.

    The swagger.json file can be in the workspace or the file system. You can provide an HTTP or file:// reference. If you right-clicked your swagger.json file in the previous step, the location is already entered. You can also drag your swagger.json file from an external file system to this field.

  3. Select the target Java EE 7 web project from the Project drop-down menu.
    Tip: Select a different project than the service project that contains the swagger.json file. Ensure that the JAX-RS 2.0 facet is enabled for the Java EE 7 target project.
  4. In the Source Folder field, enter the target source folder that is defined in the project.
  5. In the Package field, enter the Java package of the generated client code.
  6. Click Finish.

Results

You generated a JAX-RS 2.0 client in the web project that you targeted. The Generate JAX-RS Client wizard creates four packages, including a package with the suffix .api. You can use the API classes in this package to invoke REST services.
Icon that indicates the type of topic Task topic
Timestamp icon Last updated: July 17, 2017 21:58

File name: t_restapi_jaxrs.html