Calling REST APIs From Camel Routes
Get your REST API calls squared away!
Join the DZone community and get the full member experience.
Join For FreeThis article covers calling a REST API from a Camel route. We will try to call the GET endpoint below from a camel route.
http://dummy.restapiexample.com/api/v1/employees
Let's create a Spring Boot Camel microservice.
In the pom.xml
of the microservice, add the dependency below:
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-http-starter</artifactId>
<version>3.8.0</version>
</dependency>
Configuring the REST Client Route in the Microservice
restConfiguration() is used to configure the host and the port.
The route is configured to run every 10 secs and call the REST API endpoint using the GET method.
xxxxxxxxxx
package com.vignesh.cameldemob.route.b;
import org.apache.camel.builder.RouteBuilder;
import org.springframework.stereotype.Component;
public class RestAPIClientRoute extends RouteBuilder {
public void configure() throws Exception {
restConfiguration().host("dummy.restapiexample.com").port(80);
from("timer:rest-client?period=10s")
.to("rest:get:/api/v1/employees")
.log("${body}");
}
}
Testing
Start the application. You can see that the timer is triggered every 10 secs, and the REST API endpoint is called.
Opinions expressed by DZone contributors are their own.
Comments