Firstly, let’s clarify what the developers of Postman say:
“Postman is a powerful set of API testing tools that have become necessary for many developers. We make great products that help create stunning APIs and improve development productivity. Postman is used by more than a million developers worldwide, currently, this number is constantly growing. We are planning to develop other products to provide developers with the most powerful solution for developing and testing APIs.”
The current version of Postman is even more powerful than the old versions, and a lot of Pro-functionality is now available for free. Moreover, this tool was created not only for developers. Even testing automatic responses feature does not require special knowledge. This is a very simple and yet powerful tool.
Submit request
If you open this set, go to “Request Methods” and then to “GET Requests”, all the saved data will be displayed in the central part of the Postman window. Now click “Submit.” You have just sent your first request and received the first reply.
POST requests are a bit more complicated, but they are still clear and logical. This time you will use your own request. Click the plus sign to open a new tab, change the request type from GET to POST, and use https://jsonplaceholder.typicode.com/posts as the request URL. This is a free REST service that can be used for fake data. It is very useful for learning, simulating server operation, and distributing code examples.
Now you need a POST request body. Click on “Body” under the request URL, change the type to “raw” and “Text” to “JSON”. Now paste this query into the editor:
- {
- “title”: “My first POST request”,
- “body”: “Content of my first POST request!”,
- “userId”: 789
- }
Click on send. You should receive a response with your text as confirmation of the successful request. Save the query for future use. You can also create a new collection. Just click on “Save” to the right of the request URL. A save dialog box opens where you can give your request a name and create a new collection for this request.
Tests
Another great feature of Postman is the automatic query tests. Once you create a test for a request, and every time an answer comes in, Postman automatically tests it according to your case studies. Take a look at a simple example.
Add a new custom request to get POST from https://jsonplaceholder.typicode.com/posts with ID = 6 and open the “Tests” tab. On the right side of the Postman window, you will see a list of snippets. It will help you create your first, second and all subsequent tests since this code is suitable for anything. It only needs to be slightly modified depending on your needs.
In our first test, we will check if the response to our request returns the HTTP status “200” if the user ID is 1, and the post id is 6, and if the response body contains text.
- tests[“Status code is 200”] = responseCode.code === 200;
- var jsonData = JSON.parse(responseBody);
- tests[“User ID is 1”] = jsonData.userId === 1;
- tests[“Post ID is 6”] = jsonData.id === 6;
- tests[“Body matches string”] = responseBody.has(“dolorem eum magni eos aperiam quia”);
Now just click “Submit.” After the answer is received, you can click on the “Tests” tab and check if they are passed.
In this article, we wanted to show you how simple and fun it is to work with Postman!