How to Solve 5 Practical API Challenges With HttpMaster

In recent years, the number of companies that provide their services via application programming interfaces (API) is increasing rapidly, making APIs truly mainstream. To assure continuous delivery of stable and reliable API services, developers and testers often face many practical challenges. These challenges, which include chaining API requests, validating API response data and more, are usually tedious and time-consuming, but can often be solved with the use of the proper API tool. While there are many other tools to help with these issues, like SoapUI or Postman, we will look at how HttpMaster can help developers solve these problems.

Let’s dig into a few common API problems and solve them throughout this article with the help of this tool.

Chaining API Requests

One of the main challenges encountered during API development is how to connect different API requests together, in other words: API request chaining. Chaining can be used for executing multiple requests together in a batch, where every executed request obtains and uses some information from the previous request’s data. This allows developers to completely automate the testing of API endpoints which in practice are often called in a row, for example, user registration, followed by registration confirmation, followed by profile photo upload, and so on. For our first example, we’ll take an API endpoint with the PUT method that inserts a new customer into the database, for example,

‘api.httpmaster.net/customer’

which accepts customer data in its request body. We can expect that this insert will generate a new id for the customer which will be returned in response data. It is also reasonable to assume that there is an API endpoint with GET method that allows us to retrieve data of the customer by specifying its id in the URL, for example,

api.httpmaster.net/customer/<customer_id>

While manually testing these two API endpoints separately would certainly work, it would be time-consuming and it certainly does not represent the most effective solution to the problem. A better approach is to chain these two API requests together and automatically extract and use customer id from response data.

HttpMaster includes functionality to chain API requests in a way described previously. First, it is necessary to create a new chaining item and define from where data should be extracted. There are several options available, for example, response body, response header, response URL, and more. For our example we have specified that customer id is returned in response body and should be extracted from there.

Create a chaining item

Create a chaining item

Now that our chaining item has been created, we need to specify where it should be used. We will open the properties of the API endpoint to get the customer data and include the chaining item in the URL because this API endpoint accepts a customer id in its URL.

Use chaining item in URL

Use chaining item in URL

We can now execute both of these API endpoints together in a correct order; first PUT, then GET. If the results of the GET request are opened after execution has completed, we can see that the chaining item used in the URL has been replaced with the customer id of the newly created customer. This customer id value was extracted from the PUT response data and used dynamically in the GET request.

Review execution results

Review execution results

Validation of API response data

Determining whether the response data returned from our API request satisfies some predefined condition is also one of the major challenges with API development. Http status codes, response header values, response body size, and many others must often be of a specific value for an API request to be valid. Sometimes it is even necessary to validate response data on multiple conditions before considering a certain API request successful.

Janez Cas is a seasoned developer with experience in building web services and development tools.

Comments

Comments(1)