Skip to content

Files

Latest commit

1987eb4 · Mar 25, 2025

History

History
This branch is 291 commits ahead of, 211 commits behind apache/camel-spring-boot-examples:main.

rest-openapi

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Mar 25, 2025
Nov 4, 2024
Mar 17, 2025

REST DSL and OpenApi - Spring Boot example

Abstract

This example illustrates how to use Spring Boot with Camel. It provides a simple REST service that is created with Camel REST DSL and documented with OpenApi.

Introduction

The project uses the camel-spring-boot-starter dependency, a Spring Boot starter dependency for Camel that simplifies the Maven configuration.

The project also uses camel-servlet component as the HTTP transport component for Camel REST DSL.

Build

You can build this example using:

$ mvn package

Run

You can run this example using:

$ mvn spring-boot:run

You should see the following output when the application is launched:

...
2023-07-24T11:05:58.913+02:00  INFO 461599 --- [           main] o.s.b.w.e.undertow.UndertowWebServer     : Undertow started on port(s) 8080 (http)
2023-07-24T11:05:59.060+02:00  INFO 461599 --- [           main] o.a.c.s.o.OpenApiAutoConfiguration       : OpenAPI (3.0.2) created from Camel Rest-DSL v1.0.0 - User API
2023-07-24T11:05:59.153+02:00  INFO 461599 --- [           main] o.a.c.impl.engine.AbstractCamelContext   : Apache Camel 4.0.0-redhat-00001 (MyCamel) is starting
2023-07-24T11:05:59.160+02:00  INFO 461599 --- [           main] o.a.c.impl.engine.AbstractCamelContext   : Routes startup (started:5)
2023-07-24T11:05:59.160+02:00  INFO 461599 --- [           main] o.a.c.impl.engine.AbstractCamelContext   :     Started route2 (direct://update-user)
2023-07-24T11:05:59.160+02:00  INFO 461599 --- [           main] o.a.c.impl.engine.AbstractCamelContext   :     Started route1 (rest-api:///api-doc)
2023-07-24T11:05:59.160+02:00  INFO 461599 --- [           main] o.a.c.impl.engine.AbstractCamelContext   :     Started route3 (rest://get:/users)
2023-07-24T11:05:59.160+02:00  INFO 461599 --- [           main] o.a.c.impl.engine.AbstractCamelContext   :     Started route4 (rest://get:/users:/%7Bid%7D)
2023-07-24T11:05:59.160+02:00  INFO 461599 --- [           main] o.a.c.impl.engine.AbstractCamelContext   :     Started route5 (rest://put:/users:/%7Bid%7D)
2023-07-24T11:05:59.161+02:00  INFO 461599 --- [           main] o.a.c.impl.engine.AbstractCamelContext   : Apache Camel 4.0.0-redhat-00001 (MyCamel) started in 7ms (build:0ms init:0ms start:7ms)

After the Spring Boot application is started, you can open the following URL in your web browser to access the REST endpoint and retrieve a list of users: http://localhost:8080/api/users

You can also access the REST endpoint from the command line:

$ curl http://localhost:8080/api/users

The command will produce the following output:

[ {
  "id" : 1,
  "name" : "John Coltrane"
}, {
  "id" : 2,
  "name" : "Miles Davis"
}, {
  "id" : 3,
  "name" : "Sonny Rollins"
} ]

The OpenApi documentation is located at: http://localhost:8080/api/api-doc and can be retrieved with the following command:

$ curl http://localhost:8080/api/api-doc

The Spring Boot application can be stopped pressing [CTRL] + [C] in the shell.

Actuator

The actuator is available at: http://localhost:8080/actuator/ such as metrics for Prometheus: http://localhost:8080/actuator/prometheus.

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!