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