Camel Restlet component

Shardul | Jun 22, 2021 min read

๐‘๐„๐’๐“ ๐€๐๐ˆ ๐“๐ž๐ฌ๐ญ๐ข๐ง๐ 

Rest stands for Representational State Transfer. It is an architectural style and an approach for communication used in the

development of Web Services. REST has become a logical choice for building APIs. It enables users to connect and interact with cloud services efficiently.

An API or Application Programming Interface is a set of programming instructions for accessing a web-based software application. In other words, a set of commands used by an individual program to communicate with one another directly and use each other’s functions to get information.

For example, a Google website can have API for various functions like search, translations, calendars, etc.

In general API’s are like below, they have server name, paths.., etc

http://<server name>/v1/export/Publisher/Standard_Publisher_Report?format=csv

There are mainly 4 methods involve in API Testing like GET, POST, Delete, and PUT.

๐†๐„๐“

GET method is used to extract information from the given server using a given URI. While using GET request, it should only extract data and should have no other effect on the data.

๐๐Ž๐’๐“

A POST request is used to create a new entity. It can also be used to send data to the server, for example customer information, file upload, etc. using HTML forms.

๐๐”๐“

Create a new entity or update an existing one.

๐ƒ๐„๐‹๐„๐“๐„

Removes all current representations of the target resource given by a URI.
Code Pic


  1. In above code I have used get method in first route get method is used to extract information from the given server using a given URI. While using GET request, It should only extract data and should have no other effect on the data.
  2. In second route I have used post method.A POST request is used to create a new entity. It can also be used to send data to the server, for example customer information, file upload, etc. using HTML forms.
  3. We can use multiple route IDs in a CamelContext project.But it should be noted that the name of each route ID should be different.
  4. <from uri="restlet:http://localhost:8020/api/getdbdata In this line we will use Restlet component and here we will give the path of our get API along this path we hit the API via curl command.
  5. <to uri=restlet:http://dummmy.restapiexample.com/api/v1/employee/1" In this line we will give the path of our dummy api.
  6. The SetBody EIP allows us to set the body of our exchange.
  7. The SetHeader EIP allows you to set and header on our exchange.
๐ƒ๐ž๐ฉ๐ž๐ง๐๐ž๐ง๐ฒ ๐ฐ๐ก๐ข๐œ๐ก ๐ฐ๐ž ๐ก๐š๐ฏ๐ž ๐ฎ๐ฌ๐ž๐

When we send multiple requests at the same time through curl command then ๐‚๐จ๐ฆ๐ฆ๐š๐ง๐ ๐›๐ฒ ๐ฐ๐ก๐ข๐œ๐ก ๐ฐ๐ž ๐ก๐ข๐ญ ๐จ๐ฎ๐ซ ๐€๐๐ˆ

For GET METHOD- curl -X GET http://localhost:8020/api/getdbdata

For POST MEHOD - curl -d '{"name": "ram", "age":"27"}' -H "content-type:application/json" -X POST http://localhost:8010 /api/getDBData

๐ˆ๐ฌ๐ฌ๐ฎ๐ž ๐ฐ๐ž ๐ก๐š๐ฏ๐ž ๐Ÿ๐š๐œ๐ž๐

1 When I was sending data from post method via the curl command.the data was not being sent and the restlet operation failing at that time.

2 When we send multiple requests at the same time through curl command then we come to this issue.


๐Ž๐ฎ๐ญ๐ฉ๐ฎ๐ญ ๐ฐ๐ก๐ž๐ง ๐ฐ๐ž ๐ž๐ฑ๐ญ๐ซ๐š๐œ๐ญ ๐๐š๐ญ๐š ๐Ÿ๐ซ๐จ๐ฆ ๐ ๐ž๐ญ ๐ฆ๐ž๐ญ๐ก๐จ๐ ๐ฎ๐ฌ๐ข๐ง๐  ๐๐ฎ๐ฆ๐ฆ๐ฒ ๐€๐๐ˆ ๐ฏ๐ข๐š ๐œ๐ฎ๐ซ๐ฅ ๐œ๐จ๐ฆ๐ฆ๐š๐ง๐

๐‘๐ž๐Ÿ๐ž๐ซ๐ž๐ง๐œ๐ž ๐จ๐Ÿ ๐ฌ๐ข๐ญ๐ž๐ฌ ๐ฐ๐ž ๐ก๐š๐ฏ๐ž ๐ฎ๐ฌ๐ž๐

https://camel.apache.org/components/2.x/restlet-component.html