Skip to content

Latest commit

 

History

History
 
 

openapi-contract-first

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

OpenAPI Contract First: A Camel Quarkus example

{cq-description}

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

From the contract we generate Java POJO classes (using quarkus-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.

Tip
Check the Camel Quarkus User guide for prerequisites and other general information.

Start in the Development mode

$ mvn clean compile quarkus:dev

The above command compiles the project, starts the application and lets the Quarkus tooling watch for changes in your workspace. Any modifications in your project will automatically take effect in the running application.

Tip
Please refer to the Development mode section of Camel Quarkus User guide for more details.

Package and run the application

Once you are done with developing you may want to package and run the application.

Tip
Find more details about the JVM mode and Native mode in the Package and run section of Camel Quarkus User guide

JVM mode

$ mvn clean package
$ java -jar target/quarkus-app/quarkus-run.jar
...
[io.quarkus] (main) camel-quarkus-examples-... started in 1.163s.

Native mode

Important
Native mode requires having GraalVM and other tools installed. Please check the Prerequisites section of Camel Quarkus User guide.

To prepare a native executable using GraalVM, run the following command:

$ mvn clean package -Pnative
$ ./target/*-runner
...
[io.quarkus] (main) camel-quarkus-examples-... started in 0.013s.
...

How to run

Test the service endpoint from another terminal:

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

You should get some results like:

{"id":123,"name":"Tony the tiger","photoUrls":[],"status":"available"}

Feedback

Please report bugs and propose improvements via GitHub issues of Camel Quarkus project.