How to Submit a Request to REST Web API
The REST Web API test 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 such request types as POST, PUT, or PATCH. In this case, to specify the request body, navigate to the Post Data section.
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.
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.
You can submit as many requests within a test as you want. Note that all requests must be added to the test in the order they have to be executed.
To set up a multi-request test:
- First, create and save a new Rest Web API test.
- To set up a sequence of requests within the test, in the list of tests, from the test’s action menu , select Add Target.
- 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.
- 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.
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.
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.
REST API Monitoring
The majority of modern web applications use a REST API to communicate with the server and to integrate with each other. Ensuring proper quality of data in the API, we ensure the quality of the entire web service that uses it.
Let’s say you have created RESTful API for your web service, and it is necessary to control that all the API functions are working properly and available 24/7. But why do we need to test a WEB API, isn’t it easier to test a user interface for issues? Let’s discuss the most common advantages of API testing and monitoring.
The first advantage of REST API testing is that it helps to identify a particular source of an issue. By testing your API, you can find which specific function is executed with errors.
Also, with API testing you do not need to build a dedicated test environment to test your web service functionality. Opposite to UI tests that require a chain of user actions in a browser window to send a request to a web server, API testing and monitoring can be performed using automated tools to send a specific endpoint request. For example, this approach allows you to bypass such issue as false test failures occurs on the GUI level.
Although you can test all the API functions manually, it is a difficult and time-consuming process. Moreover, every time you make changes or added new features to your API the tests must be executed again to be sure the updates have not affected the API functionality. Automated REST API monitoring allows to avoid the disadvantages of manual testing and can bring your API monitoring routine on the next level.
REST API Monitoring with Dotcom-Monitor
Dotcom-Monitor offers two options for automated API performance monitoring:
- The REST Web API monitoring device.
- The Postman Collection monitoring device.
To set up RESTful API monitoring test from the scratch it is recommended to use our REST Web API monitoring device. This type of the monitoring device allows you to configure a simple HTTP request to an API endpoint with a basic authentication and POST parameters.
In case you have already used Postman to run the tests of your RESTful API services, it is recommended to import your Postman Collection to Dotcom-Monitor. Once the collection of Postman requests was imported to the system, you can configure the Postman Collection monitoring device to automate monitoring of your API services.
Although the REST Web API device supports multi-request execution, in some cases it can be tricky to configure. In its turn, if you are familiar with the tool, Postman is great to configure parametrized HTTP requests and assertion tests for REST Web API monitoring.
Thus, if you want to create a test with a complicated sequence of API calls or when an authentication other than basic authentication is required, use Postman to create a collection of API calls. Then, simply import it to the Dotcom-Monitor Postman Collection device and set up monitoring as described in the Postman Monitoring (Collection Tasks) with Dotcom-Monitor APIs. Dotcom-Monitor will execute API calls with a specified frequency (up to 1 min), generate reports, and send monitoring error notifications to a provided address.
Be sure to check out our full suite of API monitoring tools at Dotcom-Monitor to help ensure the reliability of web applications and services!