== REST DSL and OpenApi - Spring Boot example

=== Abstract

This example illustrates how to use https://projects.spring.io/spring-boot/[Spring Boot] with http://camel.apache.org[Camel]. It provides a simple REST service that is created with http://camel.apache.org/rest-dsl.html[Camel REST DSL] and documented with http://swagger.io[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:

[source,text]
----
...
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:

[source,text]
----
$ curl http://localhost:8080/api/users
----

The command will produce the following output:

[source,json]
----
[ {
  "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:

[source,text]
----
$ 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
https://camel.apache.org/support.html[let us know].

We also love contributors, so
https://camel.apache.org/contributing.html[get involved] :-)

The Camel riders!
