Testing APIs
What API testing is
API testing checks that an API gives the right answers, rejects the wrong requests, keeps its promises — and stays fast. What to test, and why "it answered" isn't enough.
API testing means sending an API requests on purpose and checking its answers — to find out whether it does what it promises before the apps and people that depend on it find out the hard way.
It sits in the middle of testing. Below it, developers' unit tests check small pieces of code. Above it, end-to-end or UI tests click through a whole app in a browser. API tests skip the screens and talk to the system the way other programs do — which makes them fast (milliseconds, not minutes), stable (no buttons that move) and close to where bugs live (the business rules are behind the API, not in the screen).
"It answered" isn't enough
The most common weak test sends a request, sees 200 OK, and passes. But a 200 can carry:
- an error message (
{ "success": false }), - the wrong data (someone else's order; yesterday's price),
- the right data in the wrong shape (
"price": "45"instead of45; a renamed field), - nothing (
{ "items": [] }when there should be ten), - an answer that took 9 seconds.
A real test says what a correct answer is and checks for it. That's what checks are for.
What to test
A useful way to think about it: for each request, ask does it do the right thing, refuse the wrong thing, keep its shape, and stay fast?
1. It does the right thing — functional tests
- The happy path: a normal, valid request gives the right status and the right data.
GET /orders/A-1001returns order A-1001 with its items and total. - Business rules: the total is the sum of the items; a discount applies only above ₹1,000; a cancelled order can't be shipped.
- State changes: after
POST /orders,GET /orders/<new id>finds it; afterDELETE, it's gone (404).
2. It refuses the wrong thing — negative tests
Real users and real programs send bad requests. A good API refuses them clearly — a 4xx with a message, never a 500 or, worse, a quiet success:
- a missing or invalid field →
400or422, naming the field; - a wrong type (
"quantity": "two"), a negative number, a very long string, an empty body; - a thing that doesn't exist →
404; - no token →
401; someone else's order →403or404, never the order; - the same thing twice (pay an invoice twice) → a
409, not a double charge.
Negative tests usually find more bugs than happy-path tests, because developers try the happy path themselves.
3. It keeps its shape — contract tests
Other teams build on the API's contract: its fields, their types, which ones are always there. A contract or schema test checks every answer still has that shape, so a renamed field is caught before the mobile app crashes. See contracts and schemas.
4. It stays fast and holds up — performance tests
An answer that's right but takes 6 seconds is still a failure for the person waiting. Response-time checks catch slow single requests; load tests find out what happens when hundreds of requests arrive at once. That's the whole third track of these lessons, starting at why test performance.
5. It's safe — security basics
You don't need to be a security expert to check the basics: requests without auth are refused; one user can't read another's data by changing an id in the URL; error answers don't show stack traces or passwords; tokens expire. (Real security testing goes much further — but these catch embarrassing, common mistakes.)
Manual, then automated
Testing usually starts by hand: you send requests, read answers, poke at edge cases. That's how you learn an API — and it's what Send is for.
Then you automate what you learned: save the requests with their checks, run them as a collection, and have them run by themselves on every change (in a pipeline). An automated test that runs a thousand times catches the bug that comes back three months later — a regression.
Key takeaways
- API tests talk to the system like other programs do — fast, stable, close to the business rules.
- A
200proves little: test that it does the right thing, refuses the wrong thing, keeps its shape, stays fast — and the basics of security. - Explore by hand first, then automate what you learned so it catches regressions.
In the app: Checks · Running a collection