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:
XML
x
1
<dependency>
2
<groupId>org.apache.camel.springboot</groupId>
3
<artifactId>camel-http-starter</artifactId>
4
<version>3.8.0</version>
5
</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.
Java
xxxxxxxxxx
1
18
1
package com.vignesh.cameldemob.route.b;
2
3
import org.apache.camel.builder.RouteBuilder;
4
import org.springframework.stereotype.Component;
5
6
7
public class RestAPIClientRoute extends RouteBuilder {
8
9
10
public void configure() throws Exception {
11
restConfiguration().host("dummy.restapiexample.com").port(80);
12
13
from("timer:rest-client?period=10s")
14
.to("rest:get:/api/v1/employees")
15
.log("${body}");
16
}
17
}
18
Testing
Start the application. You can see that the timer is triggered every 10 secs, and the REST API endpoint is called.
REST
Web Protocols
Opinions expressed by DZone contributors are their own.
Comments