Key takeaways
- An API is the set of requests a server accepts, the same requests the app's screens send behind the scenes. Testing it directly is faster and more precise than testing through the UI.
- Postman lets you send requests, inspect responses and write small tests in JavaScript, without building a framework. Free alternatives include Bruno and Insomnia.
- In about an hour you can go from your first GET request to a collection of requests with automated checks, which makes a good portfolio piece.
Why start with APIs?
When you click "Save" in a web app, the browser sends an API request, such as POST /api/profile, and the server responds with data, usually in JSON. You saw this in how the web works and in the DevTools Network panel.
Testing the API directly lets you:
- check business rules before the UI exists;
- send data the UI would never allow, like negative quantities or missing fields;
- run hundreds of checks in seconds.
Many junior job ads list "API testing (Postman)" as a requirement or a plus.
Setup
- Download Postman from postman.com, or use the web version. Create a free account.
- Create a Collection called "My first API tests". A collection is a folder of requests.
- We'll use JSONPlaceholder (
https://jsonplaceholder.typicode.com), a free fake API made for practice. It accepts requests but doesn't really save changes, so you can't break anything.
Step 1: your first GET request
In your collection, add a request:
- Method: GET
- URL:
https://jsonplaceholder.typicode.com/posts/1
Click Send. You should see:
- Status: 200 OK
- a time in milliseconds;
- a JSON body like this:
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident...",
"body": "quia et suscipit..."
}
Now try /posts/9999. You'll get 404 Not Found, the correct answer for something that doesn't exist. Testing missing and invalid IDs is a classic API check.
Step 2: your first automated checks
Open the request's Scripts tab and choose Post-response (in older Postman versions, the tab is called Tests). Add:
pm.test("status is 200", () => {
pm.response.to.have.status(200);
});
pm.test("returns post 1 with a title", () => {
const post = pm.response.json();
pm.expect(post.id).to.eql(1);
pm.expect(post.title).to.be.a("string").and.not.empty;
});
pm.test("responds in under 1 second", () => {
pm.expect(pm.response.responseTime).to.be.below(1000);
});
Click Send again and open the Test Results tab: three green passes. Change eql(1) to eql(2) and send again to see a failure. Always check that a test can fail; a test that can never fail checks nothing.
Step 3: a POST request
Add a new request:
- Method: POST
- URL:
https://jsonplaceholder.typicode.com/posts - Body → raw → JSON:
{
"title": "My first test post",
"body": "Hello from Postman",
"userId": 1
}
Send it. The expected answer is 201 Created, with your data and a new id. Add tests:
pm.test("created", () => pm.response.to.have.status(201));
pm.test("echoes the title and assigns an id", () => {
const post = pm.response.json();
pm.expect(post.title).to.eql("My first test post");
pm.expect(post).to.have.property("id");
});
Step 4: variables and environments
Hard-coding the URL in every request is painful. Create an Environment called "Practice" with a variable baseUrl = https://jsonplaceholder.typicode.com, select it, and change your URLs to:
{{baseUrl}}/posts/1
In a real job you'd have one environment per test environment, such as test and staging, and switch between them with one click.
Step 5: run the whole collection
Click the collection's Run button. The Collection Runner sends every request in order and shows all test results together. This is a small automated regression suite.
Later, you can run the same collection from the command line with Newman (newman run collection.json) or the Postman CLI, and put it in a CI pipeline.
What to test in an API: a starter list
- Happy path: valid request, expected status and data.
- Not found: IDs that don't exist → 404.
- Validation: missing required fields, wrong types, too-long text → 400 with a clear message, not 500.
- Authentication: no token or an expired token → 401; another user's data → 403 or 404.
- Response structure: all expected fields present, with the right types.
The intermediate article on API testing goes much deeper: contracts, authorisation, idempotency and how to structure a real API test suite.
A tester checked a shop's cart in the browser. The quantity field only allowed 1 to 10, and everything worked.
Then she opened DevTools, copied the POST /api/cart/items request into Postman, and changed "quantity": 2 to "quantity": -3. The API returned 200 OK, and the cart total dropped by the price of three items.
The UI blocked negative numbers; the server didn't check at all. Anyone who could send a request directly could lower their bill. The fix added server-side validation, and the tester added the negative, zero and huge quantity cases to the Postman collection so they would be checked on every build.
Lesson: the UI is not a security barrier. Testing the API directly finds the rules that only the screen enforces.
Do
Check status, important fields, and at least one negative case for every request, and make sure each test can fail.
Don't
Send requests, glance at the response and move on. Without written checks, nothing tells you when the API's behaviour changes.
Check yourself
You send POST /api/users without the required 'email' field. The API returns 500 Internal Server Error. Is that a bug? What should it return?
Show answer
Yes, it's a bug. A missing field is the client's mistake, so the server should respond with 400 Bad Request (or 422) and a clear message such as "email is required". A 500 means the server crashed on input it should have validated. Report it with the request body and the response.
