How to Submit a Request to Rest Web API

Request Type

The REST Web API task supports different HTTP methods that can be used according to your testing goals. Selecting a GET request will simply retrieve data from your Web API. Although request parameters can be included in the URL, it is recommended to use dedicated methods to push the payload to an API.

To send any custom information, change data, or trigger any flow or event, use requests types as POST, PUT, or PATCH.  In this case, to specify the request body, navigate to the Post Data section.

If you set the request type to POST, PUT, or PATCH, but do not specify the request parameters in the Post Data section, the request type will be changed back to GET upon saving the task.

Authentication

If your API requires authentication, provide the credentials in the Basic Authentication section. If token-based authentication is the method used, follow the recommendations provided for OAuth 2.0-based APIs and configure authentication parameters in a similar way.

Post Data

In this section, you can easily provide any request entities, such as JSON.

To specify the request body, just paste or enter JSON content into the field. The system will automatically parse the code and you’ ‘ll be prompted to select a content type header based on the request body type. Also, you can provide a custom content-type header if it’s necessary.

Once specified, the content type will be automatically added to the Headers section.

Creating a Collection of Requests

You can submit as many requests within a device as you want. Note that all requests must be added to the device in the order they have to be executed.

To set up a multi-request device:

  1. First, create and save a new Rest Web API device.
  2. To set up a sequence of requests within the device, in the list of devices, from the action menu  of the Rest Web API device, select Add Target (Add Task in the case of load test device).
  3. Set up the request settings and save changes. The requests will be listed on the sidebar on the device edit screen in the order they will be executed. To access the request parameters select the corresponding item on the sidebar.
  4. To add the next request from within the device’s edit interface, click the “plus” button on the sidebar.

To learn more information on multi-target device configuring and monitoring, see Adding several targets within a single device.

Results Validation

In general, it is not enough to simply make a call to an API, the purpose to make sure the API response contains data that was expected to receive. To verify the API response, it is sufficient to find some keywords which match exactly in the response. Knowing your API response content, you can provide the keywords in the Content Validation section. For details, see the Keyword article.

Use Cases

Let’s consider an email REST API as an example. To monitor the service, we need to send the POST request to the corresponding API endpoint, along with the email details in the request body. To do this, we have to provide the endpoint URL and select the POST request type.

Since the email REST API requires basic authentication, we also need to provide the credentials in the corresponding section.

In the Post Data section, we will specify the JSON array with email details and select the header type to push the payload to the API endpoint.

The next step is to specify a keyword to look for in the API response for its validation.