API testing basics with Postman
Requests, status codes, assertions and environment variables — testing the backend directly.
Most apps talk to a backend through APIs. Testing the API directly is faster and finds bugs earlier than testing only through the screen.
What to check in an API response
- Status code — 200 OK, 201 Created, 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Server Error.
- Response body — correct fields, types and values.
- Headers — content type, caching, security headers.
- Response time — within the agreed limit.
- Negative cases — missing fields, wrong types, no token, another user's data.
In Postman
Create a request (method + URL + headers + body), save it in a collection, use environment variables such as {{baseUrl}} and {{token}} to switch between QA and staging, and add tests — small scripts that assert on the response. Collections can run all requests in order, which makes a quick regression suite.
Example
Practise on any app you usePOST {{baseUrl}}/api/orders
Headers: Authorization: Bearer {{token}}
Body: { "productId": 101, "quantity": 2 }
Tests tab (JavaScript in Postman): pm.test("Status is 201", () => pm.response.to.have.status(201)); pm.test("Has order id", () => { const body = pm.response.json(); pm.expect(body.orderId).to.be.a("number"); pm.expect(body.quantity).to.eql(2); }); pm.test("Fast enough", () => pm.expect(pm.response.responseTime).to.be.below(800));
Negative: same request without the Authorization header → expect 401
What to notice
• Assertions check status, data and speed — not just "it returned".
• Variables let the same collection run on QA and staging.
• The negative case confirms the API rejects unauthenticated calls — a common security check.
Apps, IDs and data are fictional examples written for practice.
Key points
- Check status code, body, headers and response time.
- Always include negative and security cases.
- Use collections and environment variables.
- API tests make fast regression suites.
Quick check
Which status code should an API return when the auth token is missing?
401 Unauthorized means the request lacks valid authentication.
Practice task
Using any free public test API, create a collection with one GET and one POST request, and add at least three assertions to each.
Interview corner
Difference between PUT and PATCH?
PUT replaces the whole resource with the data sent; PATCH updates only the fields sent.
What would you test in a 'create user' API?
Valid creation (201 and body), required fields missing, invalid formats, duplicate email, authorization, field length limits and response time.
Original lesson written by the InfoparkDaily team · © 2026 InfoparkDaily · Free to learn — no paid course or subscription.