Example

In this example, we will learn to use post-request scripts from already available API documentation snippets in tests in Postman. Since the test snippets are available as documentation, we can directly use them to create test cases which not only saves time , but also help us to perform the testing with ease.

Steps

Step 1: Open the POSTMAN app and click on the `+` icon to create a new collection. Name the collection ‘GFG’.

Step 2: Click on Tests. Now in the right side pane, we can multiple snippets arrived. We can use any of the available snippet/test or create our own test based on our requirement. Code is written in JavaScript.

We will write 2 Tests in JavaScript from the already available snippets (API Documentation) from the right-hand side pane.

First Test: This will check whether the response time is less then 200ms

pm.test("Response time is less than 200ms", function () {
pm.expect(pm.response.responseTime).to.be.below(200);
});

Second Test: This will check whether status code is 200

pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});

Step 3: Click on Save

Step 4: When you hover, on the name of your collection, 3 dots will appear. Click on those 3 dots, and then click on “Add new request”.

Step 5: Now You can simply paste the API in the space provided and select the API type you are requesting from the dropdown like GET,POST, PUT, DELETE etc. Output will be shown in the body with the status code.

API Used:

https://jsonplaceholder.typicode.com/posts/1

Step 6: You can see the Test-execution scripts results in tab Test Results; as shown below

Output:



API documentation in Postman: Purpose and Benefits

Postman is an API(utility programming interface) development device that enables to construct, take a look at and alter APIs. It could make numerous varieties of HTTP requests(GET, POST, PUT, PATCH), store environments for later use, and convert the API to code for various languages(like JavaScript, and Python).

Similar Reads

Purpose

1. Clarity and Understanding: API documentation in Postman serves as a complete guide for builders, providing clear insights into the API’s functionalities, endpoints, and anticipated conduct. It aids in knowledge the motive and usage of each API endpoint, making it easier for builders to combine and devour the API....

Benefits

1. Enhanced Developer Experience: Well-structured documentation in Postman contributes to a wonderful developer experience in, making it easy for builders to engage with and integrate the API....

Example

In this example, we will learn to use post-request scripts from already available API documentation snippets in tests in Postman. Since the test snippets are available as documentation, we can directly use them to create test cases which not only saves time , but also help us to perform the testing with ease....

Contact Us