Three ideas that get asked in interviews
Interviews cover three ideas: the server checks everything itself, HTTP keeps no state between requests, and bugs are located in the Network tab. Client validation is bypassed by a direct request, so the API is tested separately. A token or cookie travels in every request, and tests must not depend on order. A wrong request points to the frontend, a right request with a wrong response to the backend.
API · Client-server and REST
The UI form rejects a negative amount. Does that mean the API rejects it too?
In the transfer form the amount field does not let you type a negative number, and the button stays disabled. A tester who checks only through the UI marks "passed". Then someone sends the same request with curl, the minus goes through, and money flows from the recipient to the sender. The three ideas below explain why this happens, and each answers an interview question: why API is tested separately from the UI.
1. HTTP is stateless. Every request is self-contained: by the protocol itself the server does not link it to the previous one, so everything needed (token, cookie, language, identifiers) travels in every request. Why it is designed this way: servers can be added and removed, and any of them answers any request because it does not depend on who sent what before. This is Fielding's second REST constraint. Two consequences for tests: a request can be replayed on its own if you have all the headers, and tests must not depend on the order they run in.
2. Client validation is convenience, server validation is security. A check in the form quickly tells the user about a mistake, but it runs in an environment controlled by whoever is using it. It is turned off in DevTools and bypassed by sending a request from Postman, curl or a script. So the server must validate everything as if the UI did not exist.
Where the check lives
Validation only in the UI
The form blocks the minus, but a direct request goes through. A negative amount, someone else's id and extra fields reach the database.
Validation on the server (the UI only hints)
A wrong request is rejected with the same error no matter who sent it.
Example: the minus that never existed in the UI. An autotest supposedly "checks a negative amount" but goes through the form, where the field does not let you type it. The real check is a direct request:
curl -i -X POST $BASE/api/transfers \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"fromAccount":"acc-1","toAccount":"acc-2","amount":-500}'
The bad response, which is what catches the bug:
HTTP/1.1 201 Created
Content-Type: application/json
{"id":"tr-8841","amount":-500,"status":"completed"}
How to read it. The server created the transfer and marked it completed. The UI protected, the API did not. The expected response is a client error, 400 or 422 depending on the project's agreement, saying which field is wrong, with no record in the database. The same goes for someone else's id: if fromAccount belongs to another user, the server must refuse (403 or 404), although the UI never shows other people's accounts.
The same checks in Playwright, without a browser:
// token is set via extraHTTPHeaders in playwright.config
test('negative amount is rejected', async ({ request }) => {
const res = await request.post('/api/transfers', {
data: { fromAccount: 'acc-1', toAccount: 'acc-2', amount: -500 },
});
expect(res.status()).toBe(422);
// and the state did not change: same balance
const acc = await request.get('/api/accounts/acc-1');
expect((await acc.json()).balance).toBe(5000);
});
3. Where to look for the bug. When something is wrong, the Network tab in DevTools separates three cases:
From Network to the team
This algorithm is quick because every conclusion can be checked by eye: Network shows both the request and the response. If the request replayed by hand (curl, Postman) returns the same, the bug is reproduced without the UI, and that is the strongest report.
Limits.
- "Stateless" does not mean "no sessions". The server may keep a session, but the client must pass its identifier every time. The state did not vanish, it moved into a token, a cookie or a database.
- Some bugs do not fit the three cases: races between two requests, caches, mismatches between client and server versions. Then Network is supplemented with server logs and request replays.
- UI tests are not redundant: they check that the client builds the request correctly. But they do not replace API tests, which check the server.
Common mistakes.
- Assuming a field limit in the form protects the API: the first direct request disproves it.
- Tests that depend on execution order ("first create, then update"): one test's data becomes another's precondition, and a parallel or selective run breaks such tests. Each test prepares its own data.
- Filing a bug against "backend" because of the message on the screen without looking at Network: the frontend may have built that text.
- Pasting a token into a test for days: it has an expiry, and the test fails for a reason unrelated to the logic.
Check yourself
The UI test "zero amount is not accepted" is green. Why does it not prove that the API rejects zero, and what do you add?
Answer
The form could have disabled the button, so the request never went out: only the client validation was checked. Add a direct POST with amount: 0 and check the error status and that no record was created.
The request in Network is correct, the response has the right data, but the screen shows the old amount. Which team and what is the first check?
Answer
The frontend: the response is right, so the problem is in the display. First check whether a cached or stale component state is used, and what exactly is rendered from the response.