API Testing Lesson 5

POST with a body in JSON format

Documentation for the fifth lesson

Base URL: 'http://www.answerit.ru' … 5. Resource: /api/multiply_two/ Method: POST Body: { "factor_1" : float, "factor_2" : float } Responses: 200 OK application/json { "Success":"Product of %factor_1% and %factor_2% is %product%" } where %product% = %factor_1% * %factor_2%

What is new in the documentation:

The POST method, which we have not used yet.

You already know how to change the method, so there are no difficulties here.

A Body has appeared. This means that the request will contain not only an Endpoint but also some data inside.

We create a new Resource with the POST method and pay attention to the fact that when you change the method from GET to POST, a new field appears in the lower part of the window on the left.

API testing example image from website www.aredel.com

Let's fill this field with data in JSON format according to the specification.

Body: { "factor_1" : float, "factor_2" : float }

The data must be written in JSON format

For example, let's try sending the integers 10 and 2 first. We expect to receive in response a JSON with information about what their product equals.

API testing example image from website www.aredel.com

If everything went successfully, we will learn that 10 multiplied by 2 is 20

API testing example image from website www.aredel.com

Try sending other integers and check the result.

The next step - let's try sending numbers of type float, that is, with a so-called floating point.

The simplest way - just append .0 to the numbers that already exist.

API testing example image from website www.aredel.com

As you can see, in this example nothing has changed significantly, just a .0 was added

Since we are learning to test, we will not stop and will send other numbers. This time let the digits after the . not be zeros.

For example, let's send 10.1 and 2.2

API testing example image from website www.aredel.com

The result is not quite what was expected: 10.1 multiplied by 2.2 is exactly 22.22 and there should be no 0000000000002.

Apparently, the developer relied on the multiplication inside the programming language and did not think about such a result.

Let's write him a polite email, or a message in the bug tracking system, approximately with the following content:

In response, most likely, something about Representation Error will come, the developer is not to blame and one should study the theory.

But this is also part of a tester's job.

Writing reports about found bugs is a separate story for the next lessons. The less bureaucratized a company is, the more informal the report can be. The main thing is to provide all the information needed to identify the problem.

If there is a lot of bureaucracy in a company, for example in regulated areas such as medicine, then every word can be very important in view of the adopted agreements.

Summary

In this lesson you could learn to send a POST request with a body in JSON format.

Before this, acquaintance with JSON was limited to getting data from the server, and now you can already write a simple JSON according to the specification yourself.

You found a candidate for a bug - congratulations! And wrote a small report.

A big request - do not send too many requests. I am not sure what load the site will withstand on my plan.

Article author: Andrei Olegovich