| == Spring Boot Example with Camel REST DSL, Geocoder and Swagger |
| |
| === Introduction |
| |
| 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], using the http://camel.apache.org/geocoder.html[Geocoder component] and documented with http://swagger.io[Swagger]. |
| |
| The project uses the `camel-spring-boot-starter` and `camel-geocoder-starter` dependencies as Spring Boot starter dependencies for Camel that simplify the Maven configuration. |
| |
| The project was based on it's `camel-example-spring-boot-rest-swagger` sibling. |
| |
| === 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: |
| |
| ---- |
| [...] |
| . ____ _ __ _ _ |
| /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ |
| ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ |
| \\/ ___)| |_)| | | | | || (_| | ) ) ) ) |
| ' |____| .__|_| |_|_| |_\__, | / / / / |
| =========|_|==============|___/=/_/_/_/ |
| :: Spring Boot :: (v2.0.0.RELEASE) |
| [...] |
| 2018-03-30 16:28:56.354 INFO 29880 --- [ main] o.a.c.e.springboot.geocoder.Application : Started Application in 4.806 seconds (JVM running for 5.435) |
| ---- |
| |
| After the Spring Boot application is started, you can open the following URL in your web browser to access the REST endpoint and request the address for "Paris": http://localhost:8080/camel/geocoder/?address=Paris |
| |
| You can also access the REST endpoint from the command line: |
| |
| $ curl http://localhost:8080/camel/geocoder/?address=Paris |
| |
| You'll need to setup the google Maps API credentials to make this example work. |
| |
| The command will produce the following output: |
| |
| ---- |
| { |
| "status" : "OK", |
| "results" : [ { |
| "types" : [ "locality", "political" ], |
| "formattedAddress" : "Paris, France", |
| "addressComponents" : [ { |
| "longName" : "Paris", |
| "shortName" : "Paris", |
| "types" : [ "locality", "political" ] |
| }, { |
| "longName" : "Paris", |
| "shortName" : "Paris", |
| "types" : [ "administrative_area_level_2", "political" ] |
| }, { |
| "longName" : "Île-de-France", |
| "shortName" : "Île-de-France", |
| "types" : [ "administrative_area_level_1", "political" ] |
| }, { |
| "longName" : "France", |
| "shortName" : "FR", |
| "types" : [ "country", "political" ] |
| } ], |
| "geometry" : { |
| "location" : { |
| "lat" : 48.856614, |
| "lng" : 2.3522219 |
| }, |
| "locationType" : "APPROXIMATE", |
| "viewport" : { |
| "southwest" : { |
| "lat" : 48.815573, |
| "lng" : 2.225193 |
| }, |
| "northeast" : { |
| "lat" : 48.9021449, |
| "lng" : 2.4699208 |
| } |
| }, |
| "bounds" : { |
| "southwest" : { |
| "lat" : 48.815573, |
| "lng" : 2.224199 |
| }, |
| "northeast" : { |
| "lat" : 48.9021449, |
| "lng" : 2.4699208 |
| } |
| } |
| }, |
| "partialMatch" : false |
| } ] |
| } |
| ---- |
| |
| The Swagger documentation is located at: http://localhost:8080/camel/api-doc and can be retrieved with the following command: |
| |
| $ curl http://localhost:8080/camel/api-doc |
| |
| The Spring Boot application can be stopped pressing `[CTRL]`+`[C]` in the shell. |
| |
| === 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! |