Skip to content

Latest commit

 

History

History
67 lines (38 loc) · 2.03 KB

File metadata and controls

67 lines (38 loc) · 2.03 KB

Camel Example OpenAPI Contract First

This example uses Camel to expose REST APIs from an existing OpenAPI specification (contract first).

From the contract we generate Java POJO classes (using maven plugin, see pom.xml).

In the Camel route PetStoreRoute.java we use Rest DSL using OpenAPI in contract-first mode. This makes it possible to expose all the APIs very easily, and map this to corresponding Camel routes via direct:operationId naming convention.

The example uses the Petstore OpenAPI example which comes with 18 APIs. This example has only implemented 2 of these APIs, and to ignore the remaining APIs. This is handy during development, so you can implement the APIs one by one.

How to run

You can run this example using

mvn spring-boot:run

To call the API

You can call the Rest APIs such as

curl http://0.0.0.0:8080/api/v3/pet/123

Which returns information about a pet.

You can also update an existing PET such:

curl -XPUT -H "Content-Type: application/json" --data "@daisy.json" http://0.0.0.0:8080/api/v3/pet

Camel CLI

This application is integrated with the Camel CLI (camel-jbang) via the camel-cli-connector-starter dependency (see pom.xml). This allows to use the Camel CLI to manage this application, such as:

$mvn spring-boot:run

And then use the CLI to see status:

$camel get
  PID   NAME           CAMEL  PLATFORM            PROFILE  READY  STATUS   RELOAD  AGE  ROUTE  MSG/S  TOTAL  FAIL  INFLIGHT  LAST  DELTA  SINCE-LAST
 87918  CamelPetStore  4.6.0  Spring Boot v3.2.4            1/1   Running       0   7s    3/3   0.00      0     0         0                    -/-/-

To see which Rest APIs that are available in the running Camel application, you can use camel-jbang as follows:

$camel get service

Help and contributions

If you hit any problem using Camel or have some feedback, then please let us know.

We also love contributors, so get involved :-)

The Camel riders!