𝐑𝐄𝐒𝐓 𝐀𝐏𝐈 𝐓𝐞𝐬𝐭𝐢𝐧𝐠
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.
- 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.
- 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.
- 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.
<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.<to uri=restlet:http://dummmy.restapiexample.com/api/v1/employee/1"
In this line we will give the path of our dummy api.- The SetBody EIP allows us to set the body of our exchange.
- The SetHeader EIP allows you to set and header on our exchange.
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