Code Monkey home page Code Monkey logo

product-catalog-fuse's Introduction

Introduction

This is a demo showing how to build a Fuse camel service following a contract first approach. This demo is based on the article here but uses my own database structure that I use in other demos.

Creating the Open API Spec

To create the Open API specification we deploy the Red Hat API Designer into OpenShift. If you do not have OpenShift, you can use APICurio which is the upstream version of Red Hat API Designer.

To create an example of the Open API spec, click the New API button as per below:

API Designer New API

And then click the "Add a data type" button as per below:

API Designer New Data Type

Finally using the example provided below, fill out the screen as per the image.

{
    "id": 0,
    "name": "iPhone 12",
    "description": "Apple iPhone 12",
    "price": 999.99,
    "category_id": 0,
    "created": "2016-12-20",
    "modified": "2016-12-20 07:02:28.000000"
}

API Designer New Data Type Example

Make sure the Rest Resource button is selected so that it will generate a skeleton CRUD interface for you.

At this point you can start tailoring the API as you see fit, a complete example is in the stub/src/spec/product.json.

Building the code

To build the code, first you need to compile and generate the stub. You can do this using the following command:

cd stub
mvn camel-restdsl-openapi:generate
mvn package install

This will generate some classes including camel REST DSL routes. If you look at the generated code, you will see that the REST DSK invokes various direct routes. These are implemented in the fuse-impl project allowing us to keep our generated code separate from the implementation. This enables architects to iterate on the API design while minimizing the impact to developers.

Once you have compiled the stub you can then compile the implementation:

cd fuse-impl
mvn package

Deploying the code to OpenShift

To deploy the code to OpenShift we will use a binary build, all of the manifests are provided in the /manifests folder. Deploying is simply using kustomize:

kustomize build manifests/app | oc apply -f -`

product-catalog-fuse's People

Contributors

gnunn1 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.