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

You can use WebSphere Developer Tools to generate a Java API for RESTful Web Services (JAX-RS) 2.0 client into a web project. This JAX-RS 2.0 client is based on a REST API definition file that is named swagger.json.

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. In the Swagger Definition field, enter the location of your swagger.json file.

    The swagger.json file can be in the workspace or the file system, or it can be an HTTP or file:// reference.

  3. Select the target project type from the Project drop-down menu.
    Tip: Generate client code in different project than the service project that contains the swagger.json file.
  4. In the Source Folder field, enter the target source folder that is defined in the project.
  5. In the Package field, enter the location of the web package.
  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_name.api file. You can use the API classes in the package_name.api file to invoke REST services.

Feedback