Chapter 4. Implementing, building, and deploying a Fuse application based on a REST API

You can use Red Hat Fuse API Designer to generate a Camel Fuse project based on a REST API definition. In your Fuse development environment, you can complete the Camel routes and Rest DSL API. Finally, you can build the project and deploy the resulting application to Fuse on OpenShift.

Prerequisites

  • You have an existing API definition, which complies with the OpenAPI 3 (or 2) specification. For example, an openapi-spec.json file that you created with API Designer.
  • API Designer is installed and running on your local OpenShift cluster.
  • You have an existing OpenShift project with API Designer added as a service.
  • You have installed Maven and Red Hat Fuse.

The following topics describe how to implement, build, and deploy a Fuse application based on a REST API:

4.1. Uploading an API definition to API Designer

You can upload an existing API definition to API Designer.

Prerequisites

  • You have an existing API definition, which complies with the OpenAPI 3 (or 2) specification. For example, an openapi.json file that you created with API Designer.
  • API Designer is installed and running on your local OpenShift cluster.
  • You have an existing OpenShift project with API Designer added as an application.

Procedure

  1. In your OpenShift web console, open the project that contains API Designer.
  2. Open the API Designer console. In the list of applications for the project, click the URL under apidesigner. For example: https://apidesigner-myproject.192.168.64.38.nip.io

    The API Designer console opens in a separate web browser tab or window.

  3. Click Open API.

    A file manager window opens.

  4. In the file manager window:

    1. Navigate to the folder that contains the existing OpenAPI definition file, for example, openapi.json.
    2. Select the OpenAPI definition file and then click Open.

      The OpenAPI definition opens in the API Designer console.

4.2. Generating a Fuse Camel project from API Designer

You can use API Designer to generate a Fuse Camel project based on an API definition.

Prerequisites

  • API Designer is installed and running on your local OpenShift cluster.
  • You have an existing OpenShift project with API Designer added as an application.
  • You have created or opened an API definition file in the API Designer console.

Procedure

In the API Designer console:

  1. Click Generate.
  2. Select Fuse Camel Project from the drop-down list.

API Designer generates a camel-project.zip file and downloads it to your local default download folder.

The zip file contains a Fuse Camel project that provides a default skeleton implementation of the API definition using Camel’s Rest DSL and includes all resource operations. The project also includes the original OpenAPI definition file that you used to generate the project.

4.3. Completing the API Designer-generated Camel project

API Designer generates a Fuse project that provides a default skeleton implementation of the API definition using Camel’s Rest DSL and covering all resource operations. In your Fuse development environment, you complete the project.

Prerequisites

  • You have a camel-project.zip file generated by API Designer.
  • (Optional) You have installed Red Hat Developer Studio with Fuse Tooling.

Procedure

  1. Unzip the API Designer-generated camel-project.zip file to a temporary folder.
  2. Open Red Hat Developer Studio.
  3. In Developer Studio, select FileImport.
  4. In the Import dialog, select MavenExisting Maven Projects.
  5. Open the project’s camel-context.xml file in the editor view.
  6. Click the REST tab to edit the Rest DSL components.

    For information on defining REST services, see the "Defining REST services" section of the Apache Camel Development Guide.

    For information on extending JAX-RS endpoints with Swagger support, see the Apache CXF Development Guide.

    For information on using the Fuse Tooling REST editor, see the "Viewing and editing Rest DSL components" section of the Tooling User Guide.

  7. In the Design tab, edit the Camel routes.

    For information on editing Camel routes, see the "Editing a routing context in the route editor" section of the Tooling User Guide.

4.4. Building and deploying a REST service

After you complete the Fuse project, you can build and deploy the project in OpenShift.

Prerequisites

  • You have a complete, error-free Fuse project that defines a REST service.
  • You have installed Java 8 JDK (or later) and Maven 3.3.x (or later).

Procedure

If you have a single-node OpenShift cluster, such as Minishift or the Red Hat Container Development Kit, installed and running, you can deploy your project there.

To deploy this project to a running single-node OpenShift cluster:

  1. Log in to your OpenShift cluster:

    $ oc login -u developer -p developer
  2. Create a new OpenShift project for the project. For example, the following command creates a new project named test-deploy.

    $ oc new-project test-deploy
  3. Change the directory to the folder that contains your Fuse Camel project (for example, myworkspace/camel-project) :

    $ cd myworkspace/camel-project
  4. Build and deploy the project to the OpenShift cluster:

    $ mvn clean fabric8:deploy -Popenshift
  5. In your browser, open the OpenShift console and navigate to the project (for example, test-deploy). Wait until you can see that the pod for the camel-project application has started.
  6. On the project’s Overview page, locate the URL for the camel-project application. The URL uses this form: http://camel-project-MY_PROJECT_NAME.OPENSHIFT_IP_ADDR.nip.io.
  7. Click the URL to access the service.