What is REST? What is REST Client? What is REST Server? What is Restito? How to test REST client using Restito? Advantages of using Restito Framework for REST client testing Disadvantages of using Restito Framework for REST client testing

Before learning about Restito Framework for REST client testing, let us first learn a few basics.

What is REST Client?

REST Client is a method or a tool to invoke a REST service API that is exposed for communication by any system or service provider. For example: if an API is exposed to get real time traffic information about a route from Google, the software/tool that invokes the Google traffic API is called the REST client.

What is REST Server?

It is a method or an API that is exposed to communication by any system or service provider. For example, Google exposes an API to get real time traffic information on a given route. Here, the Google server needs to be up and running to listen to any requests to the exposed API from different clients.

Example:

It is time to establish a complete End-to-End scenario from the above definitions. Let us consider a taxi booking applications like Uber as a company needs real time information on the traffic situation around the routes that a given vehicle is located in.

Rest Client:

Here the client is an Uber mobile application the driver has logged on to. This app sends a request to the REST API exposed by Google maps to get the real time data. For example, A HTTP GET request.

Rest Server:

In this example, Google is the Service provider, and Google maps’ API responds with the required details to Uber app’s request. Both the client and server are equally important in REST communication. Here, we have implemented examples for automation testing of only the REST Client. For testing REST server, refer to https://www.guru99.com/top-6-api-testing-tool.html.

What is Restito?

Restito is a framework developed by Mkotsur. It is a lightweight app to help you execute any kind of HTTP Request. You can use Restito to test your REST APIs and to search problems in your application or your network.

How to test REST client using Restito?

Let us divide the exercise into the following 4 steps:

Create a HTTP client and method to send a HTTP GET request to any server endpoint. For now, consider the endpoint to be http://localhost:9092/getevents.

Start a Restito server to listen and capture the requests sent to the endpoint ‘getevents’ in localhost http://localhost:9092/getevents.

Create a test class to test the above client. Invoke the HTTP client ‘sendGETRequest’ method to initiate a GET request to the API ‘getevents’.

Validate the HTTP GET call using Restito framework.

Let us deep dive into each of the above steps. Step 1) Create a HTTP client and method to send HTTP GET request to any server endpoint. ========== JAVA CODE Starts =========== ========== JAVA CODE Ends =========== Step 2) Start a Restito server to listen and capture the requests sent to the endpoint ‘getevents’ in localhost http://localhost:9092/getevents. ========== JAVA CODE Starts =========== ========== JAVA CODE Ends =========== Step 3) Create a test class to test the above client. Invoke the HTTP client sendGETRequest method to initiate a GET request to the API ‘getevents’. ========== JAVA CODE Starts =========== ========== JAVA CODE Ends =========== Step 4) How to validate GET request with Headers and POST request with the body using Restito framework. ========== JAVA CODE Starts =========== ========== JAVA CODE Ends ===========

Advantages of using Restito Framework for REST client testing

Here are pros/benefits of Restito Framework for ReST client testing

We do not need the actual REST server to be developed to test the REST Client. Restito provides strong and varied utilities and methods to mock different behavior of a Server. For example: To test how the REST client behaves when Server responds with HTTP 404 error or HTTP 503 error. Restito servers can be set up in few milliseconds and can be terminated after the tests are completed. Restito supports all types of HTTP method contents like compressed, non-compressed, unified, application/text, application/JSON, etc.

Disadvantages of using Restito Framework for REST client testing

Here are cons/drawback of Restito Framework for ReST client testing

The REST client source should be tweaked to consider ‘localhost’ as a server machine. Opening server in any port may conflict if we use some commonly used port like ‘8080’ or ‘9443’ etc. It is advised to use ports like 9092 or 9099, which are not commonly used by other tools.

Summary:

REST stands for “REpresentational State Transfer” which is a new standard way of communication between any two systems at a given point of time. REST Client is a method or a tool to invoke a REST service API that is exposed to communication by any system or service provider. In RestServer method or an API that is exposed for communication by any system or service provider. Restito is a lightweight app to help you execute any kind of HTTP Request Create a HTTP client and method to send a HTTP GET request to any server endpoint Start a Restito server to listen and capture the requests sent to the endpoint ‘getevents.’ Start a Restito server to listen and capture the requests sent to the endpoint ‘getevents’ in localhost Here, we have implemented examples for automation testing of only the REST Client. We do not need the actual REST server to be developed to test the REST Client. The REST client source should be tweaked to consider ‘localhost’ as a server machine.