{"id":48,"date":"2025-06-03T13:04:21","date_gmt":"2025-06-03T13:04:21","guid":{"rendered":"https:\/\/qaplaybook.com\/?p=48"},"modified":"2025-06-03T13:05:03","modified_gmt":"2025-06-03T13:05:03","slug":"writing-api-tests-with-postman-with-examples","status":"publish","type":"post","link":"https:\/\/qaplaybook.com\/index.php\/2025\/06\/03\/writing-api-tests-with-postman-with-examples\/","title":{"rendered":"Writing API Tests with Postman (With Examples)"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">\ud83d\ude80 Why API Testing Matters<\/h3>\n\n\n\n<p>API testing is a <strong>must-have skill<\/strong> for modern QA professionals. It helps you test the <em>logic and functionality<\/em> behind the user interface \u2014 often before the UI is even built.<\/p>\n\n\n\n<p><strong>Postman<\/strong> is one of the easiest tools to start with. Whether you&#8217;re a manual tester or learning automation, Postman helps you send requests, validate responses, and even write test scripts \u2014 all without needing to write full code.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udd27 What Is Postman?<\/h2>\n\n\n\n<p>Postman is a free API client that lets you:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Send requests to REST APIs<\/li>\n\n\n\n<li>Inspect responses (status, body, headers)<\/li>\n\n\n\n<li>Write basic tests using JavaScript<\/li>\n\n\n\n<li>Group requests into collections and environments<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u2705 Step-by-Step: Writing Your First API Test in Postman<\/h2>\n\n\n\n<p>Let\u2019s go through an example using a public API:<br>\ud83d\udd17 <a>https:\/\/jsonplaceholder.typicode.com<\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 1: Set Up Postman<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Download Postman from <a>postman.com<\/a><\/li>\n\n\n\n<li>Open the app and create a free account<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 2: Make a Simple GET Request<\/strong><\/h3>\n\n\n\n<p>Let\u2019s get a list of fake posts from JSONPlaceholder:<\/p>\n\n\n\n<p><strong>URL:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">arduinoCopyEdit<code>https:\/\/jsonplaceholder.typicode.com\/posts\n<\/code><\/pre>\n\n\n\n<p><strong>Method:<\/strong><br><code>GET<\/code><\/p>\n\n\n\n<p>Click <strong>Send<\/strong> \u2014 you\u2019ll see a JSON response containing posts.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 3: Write a Test to Validate the Response<\/strong><\/h3>\n\n\n\n<p>Scroll down to the <strong>Tests<\/strong> tab and paste this code:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">javascriptCopyEdit<code>pm.test(\"Status code is 200\", function () {\n    pm.response.to.have.status(200);\n});\n\npm.test(\"Response has at least one post\", function () {\n    var jsonData = pm.response.json();\n    pm.expect(jsonData.length).to.be.above(0);\n});\n<\/code><\/pre>\n\n\n\n<p>\ud83d\udd0d <strong>What this does:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Asserts that the status code is <code>200<\/code><\/li>\n\n\n\n<li>Checks that the response contains at least one post<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 4: Test a POST Request<\/strong><\/h3>\n\n\n\n<p>Let\u2019s send a <strong>POST<\/strong> request to create a new post.<\/p>\n\n\n\n<p><strong>URL:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">arduinoCopyEdit<code>https:\/\/jsonplaceholder.typicode.com\/posts\n<\/code><\/pre>\n\n\n\n<p><strong>Method:<\/strong><br><code>POST<\/code><\/p>\n\n\n\n<p><strong>Body \u2192 raw \u2192 JSON:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">jsonCopyEdit<code>{\n  \"title\": \"QA Playbook\",\n  \"body\": \"Learning API testing with Postman\",\n  \"userId\": 1\n}\n<\/code><\/pre>\n\n\n\n<p><strong>Tests Tab:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">javascriptCopyEdit<code>pm.test(\"Status code is 201\", function () {\n    pm.response.to.have.status(201);\n});\n\npm.test(\"Post contains correct title\", function () {\n    var jsonData = pm.response.json();\n    pm.expect(jsonData.title).to.eql(\"QA Playbook\");\n});\n<\/code><\/pre>\n\n\n\n<p>\u2705 This validates the response from a simulated post creation.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\uddea More Test Snippets for Beginners<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Check Response Time<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">javascriptCopyEdit<code>pm.test(\"Response time is less than 500ms\", function () {\n    pm.expect(pm.response.responseTime).to.be.below(500);\n});\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Check Content Type Header<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">javascriptCopyEdit<code>pm.test(\"Content-Type is application\/json\", function () {\n    pm.response.to.have.header(\"Content-Type\");\n});\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Validate a Property in the Response<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">javascriptCopyEdit<code>pm.test(\"User ID is 1\", function () {\n    var jsonData = pm.response.json();\n    pm.expect(jsonData.userId).to.eql(1);\n});\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udca1 Bonus Tips<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use <strong>Environment Variables<\/strong> for dynamic data (e.g., <code>{{base_url}}<\/code>)<\/li>\n\n\n\n<li>Save your requests to <strong>Collections<\/strong> to reuse them<\/li>\n\n\n\n<li>Export your tests and share with your team<\/li>\n\n\n\n<li>Integrate with <strong>Newman CLI<\/strong> to run Postman tests from the command line<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udcc1 Common Use Cases for Postman in QA<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Use Case<\/th><th>Postman Feature<\/th><\/tr><\/thead><tbody><tr><td>Validate API response format<\/td><td><code>Tests<\/code> with <code>pm.response.json()<\/code><\/td><\/tr><tr><td>Check auth\/login APIs<\/td><td>Use <code>Authorization<\/code> tab<\/td><\/tr><tr><td>Automate test runs<\/td><td>Use <strong>Newman CLI<\/strong> + scripts<\/td><\/tr><tr><td>Mock APIs for frontend devs<\/td><td>Postman&#8217;s Mock Server feature<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83c\udfaf Final Thoughts<\/h2>\n\n\n\n<p>API testing doesn\u2019t have to be overwhelming. Postman makes it simple to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Explore and understand how APIs work<\/li>\n\n\n\n<li>Validate backend logic without waiting for the UI<\/li>\n\n\n\n<li>Build confidence in testing more than just interfaces<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ud83d\ude80 Why API Testing Matters API testing is a must-have skill for modern QA professionals. It helps you test the logic and functionality behind the user interface \u2014 often before the UI is even built. Postman is one of the easiest tools to start with. Whether you&#8217;re a manual tester or learning automation, Postman helps &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-48","post","type-post","status-publish","format-standard","hentry","category-test-management","no-thumb"],"_links":{"self":[{"href":"https:\/\/qaplaybook.com\/index.php\/wp-json\/wp\/v2\/posts\/48","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qaplaybook.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qaplaybook.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qaplaybook.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qaplaybook.com\/index.php\/wp-json\/wp\/v2\/comments?post=48"}],"version-history":[{"count":1,"href":"https:\/\/qaplaybook.com\/index.php\/wp-json\/wp\/v2\/posts\/48\/revisions"}],"predecessor-version":[{"id":49,"href":"https:\/\/qaplaybook.com\/index.php\/wp-json\/wp\/v2\/posts\/48\/revisions\/49"}],"wp:attachment":[{"href":"https:\/\/qaplaybook.com\/index.php\/wp-json\/wp\/v2\/media?parent=48"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaplaybook.com\/index.php\/wp-json\/wp\/v2\/categories?post=48"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaplaybook.com\/index.php\/wp-json\/wp\/v2\/tags?post=48"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}