401 means the client is not authenticated and 403 means authenticated but without rights; PUT replaces a resource entirely and PATCH changes some fields. Idempotency concerns the server state, not the response code, so a second DELETE may return 404. A strong short answer has three layers: the definition, the consequence and how an automated test checks it.
API · Interview questions in brief
You are asked about PUT and PATCH, 401 and 403. How do you answer briefly and confidently?
The interviewer asks "PUT or PATCH?", the candidate gives a definition and stops. A pause, the next question, and the talk stays at textbook level. Basic API questions are almost never the goal: they are a way to see in a minute whether practice stands behind the words. This lesson gives an answer template, a table of typical questions with the follow-ups to expect, and a breakdown of two traps.
How an answer works and why
A short answer has three layers. The first, the definition, answers the literal question. The second, the consequence, shows that you understand why it was designed so. The third, the check, moves the talk to your experience: a request, a status, what exactly you compare. The interviewer usually digs from the third layer, so it is better to give it yourself before being asked.
Three layers of an answer
Figure 1. Only the first layer sounds like a textbook; the third shows practice.
Typical questions and what comes next
Question
Short answer
The follow-up
How does client-server architecture work?
The client sends an HTTP request, the server checks authorisation, runs the logic, uses the database and returns a response with a status. HTTP is stateless, so the token goes with every request.
Where is the session kept? Cookie versus token?
What is REST?
An API style: data are resources behind URLs, the actions are set by HTTP methods, the server keeps no client state between requests, the format is usually JSON.
How does it differ from GraphQL or gRPC?
PUT vs PATCH?
PUT replaces the whole resource and is idempotent. PATCH changes some fields, and its idempotency depends on the format of the change.
What happens to a field missing from a PUT body?
What is idempotency?
A repeated identical request does not change the state beyond the first one. GET, PUT, DELETE yes; POST no, so payments need an Idempotency-Key.
The second DELETE returns 404: is that a violation?
401 vs 403?
401: not authenticated. 403: authenticated but not allowed.
Which status for someone else's order?
400 vs 422?
400: the request is malformed (broken JSON, a missing field). 422: the shape is fine, but a domain rule is violated.
Does every team draw the line the same way?
A 500 on invalid data: is it a bug?
Yes. Invalid input should give a 4xx with an explanation, while 500 means an unhandled failure on the server.
What goes into the bug report?
Worked example: 401 and 403 in one case
Instead of definitions, show two requests you would really send. A request without a token to a protected resource, and the same kind of request with a regular user's token to an admin action:
The WWW-Authenticate header in a 401 is not decoration: by the HTTP specification such a response has to include it, and the client learns the authentication scheme from it. The second request carried a valid token, so the server knows who it is and refuses by role. Compare two answers to the question:
Two ways to answer about 401 and 403
Weak answer
"401 is no access, 403 is also no access"
Two codes merge into one. The interviewer asks at once: and what should a test do with an expired token?
Strong answer
"Who are you" versus "what may you do"
401: the server does not know who this is (no token, or it expired). 403: it knows, but the role forbids the action. I check both without a token and with a token of another role.
Figure 2. The strong answer already contains a check you can run.
The limits of short answers
Idempotency. A second DELETE may give 404, and that is not a violation: what stays the same is the server state (the resource is gone), not the response code.
PATCH. The instruction "add 10 to the balance" is not idempotent, while "set the balance to 110" is. That is why the table says "depends" for PATCH.
400 versus 422. The HTTP specification defines 422 as "the request is understood but its content cannot be processed". Teams draw the line with 400 differently, so a project relies on its contract and requires consistency, not one "correct" code.
403 versus 404. To avoid confirming that someone else's resource exists, a server may return 404 instead of 403. That is a deliberate decision, not a mistake.
Common mistakes
Memorising the table without being able to say "why": the first follow-up exposes it.
Answering for longer than a minute: the listener loses the thread and the question still has no example.
Mixing up 401 and 403 in your own tests: a "different user" test expects 401 and masks a missing role check.
Calling everything "safe" idempotent: safe methods change nothing, while PUT and DELETE do change state but do not change it again on a repeat.
Check yourself
A user sent DELETE /orders/42 twice. The first time 204, the second 404. Is that a violation of idempotency?
Answer
No. Idempotency is about server state: after the first and the second request the resource is gone either way. The response code may differ. It would be a violation if the second DELETE removed something else.
The token has expired. Which status to expect and what does it say about the server?
Answer
401: the server cannot establish the identity because the credentials are not valid. The role is irrelevant here. A 403 would mean the server "knew" the user from an expired token, which is already suspicious.
Related lessons: “HTTP methods, idempotency, PUT vs PATCH”, “401 vs 403, 400 vs 422, 500 vs 503”, “Client and server: who is responsible for what”.
In an interview.Junior: I give the definition in one sentence and add an example request: 401 without a token, 403 with a token of another role. PUT replaces the whole resource, PATCH changes some fields. Middle/Senior: After the definition I name the consequence and the limit: idempotency is about state, not the response code, PATCH depends on the format of the change, and 403 is sometimes deliberately replaced with 404. I show how an automated test checks it and agree with the team where the line between 400 and 422 runs.
Postman and automation
Postman is explained as one chain, from variables and scripts to the Runner and Newman in CI, where each link solves the previous one's problem. When variable names clash, the narrower scope wins: Local, Data, Environment, Collection, Global. Newman returns a non-zero exit code when a test fails, so the build turns red without extra scripts, and secrets are passed with --env-var.
API · Interview questions in brief
From variables to CI: how do you tell the Postman story as one connected chain?
Questions about Postman rarely come alone: after "what variable scopes are there" comes "how do you pass a token between requests", then "how do you run it on data" and "how does it end up in CI". A candidate who answers each separately sounds like a list of features. One who holds a single story from a variable to a pipeline sounds like someone who built it. The lesson gives that story and a table of short answers to go with it.
How the chain works and why
Each link solves the problem of the previous one. A hard-coded address and token break when the environment changes, so variables appear. The token exists only after login, so scripts are needed to save a value from the response. One scenario for ten users without copying requests is a Runner with a data file. And so that none of this depends on someone remembering to press a button, Newman runs the collection in the pipeline and returns an exit code.
The chain from a variable to a pipeline
Figure 1. Each step exists because the previous one does not solve the next problem.
Question
Short answer
Variable scopes in Postman?
Global, Collection, Environment, Data, Local. With equal names the narrower scope wins: Local over Data, Data over Environment, Environment over Collection, Collection over Global.
How do you pass data between requests?
Save the value in post-response via pm.environment.set, use {{name}} in the next request.
Pre-request vs post-response?
Pre-request prepares the request: data, a signature, a token. Post-response checks the response and saves values.
How do you run a collection in CI?
Export the collection and the environment, run newman run with the JUnit reporter; pass secrets through --env-var from CI variables.
What do you check besides the status?
The schema, field types and values, headers, response time, absence of sensitive data and that the change was really saved.
Worked example: the token is not the one you expected
The Login request saves the token in post-response, the next requests take it as {{token}}:
// post-response of the Login requestconst body = pm.response.json();
pm.test('has a token', () => pm.expect(body.token).to.be.a('string'));
pm.collectionVariables.set('token', body.token);
// in the next request: Authorization: Bearer {{token}}
The build in CI fails with 401 although everything is green locally. The cause is scopes: the environment file for CI already holds a token variable with an old value, and the script writes the new value into a collection variable (pm.collectionVariables.set), which has lower priority. The narrower scope, Environment, overrides it, and the requests go with the old token. Diagnosis: compare in the Postman console or in the Newman output the value that was substituted with what Login returned. Fix: store into the scope the request reads (pm.environment.set) and do not keep the token in the environment file at all.
Newman returns a non-zero exit code if at least one test of the collection failed, so the build step turns red without extra scripts. CI shows the JUnit file as a test report.
Limits and alternatives
Postman or code: two legitimate options
Postman
Exploration and quick checks
Quick to assemble a request, look at the response, show a colleague. Fits a small smoke set and manual scenarios.
Code
A large regression suite
Review in git, types, shared helpers, running next to UI tests. Changes to tests are visible in a diff.
Figure 2. This is not "good versus bad": the tool depends on the size of the suite and the team.
Newman remains an open-source tool, and Postman also has its own CLI; for an interview it is enough to understand that a collection runs from the command line without the UI.
Postman scripts are hard to review and reuse: the logic lives inside the collection JSON.
Secrets in an exported environment end up in git unless removed before the export.
Common mistakes
A hard-coded host and token in requests: the collection works only on one environment.
Checking only the status: a 200 with an empty or wrong body passes.
Shared variables between Runner iterations without cleanup: the second data row sees leftovers of the first.
Exporting an environment with real secrets into the repository.
Check yourself
A token variable exists both in the collection and in the environment with different values. Which one goes into the request?
Answer
The environment: it is narrower than the collection and wins. So a script that writes the token into a collection variable has no effect while the environment holds a token.
The test is green in Postman and red in Newman in CI. Name two causes you check first.
Answer
Different environments or variable values (the wrong environment file, a secret not passed via --env-var) and the order or dependency between requests (the collection ran partially or without the data file). Then I read the Newman log and compare the substituted values.
Related lessons: “Variable scopes and secrets”, “Pre-request, post-response and basic checks”, “Newman and CI”, “Postman's limits”.
In an interview.Junior: I tell it as a chain: variables and environments, scripts save the token and ids, Runner runs the data, Newman runs the collection in CI. Middle/Senior: I add the limits: scope priority and the old-token trap, secrets through --env-var, the JUnit report and exit code as a build gate. To "Postman or code" I answer that Postman is for exploration and a small smoke set, while a large regression stays in code with review in git.
How do you build an API automation framework and which layers does it have?
An API test framework consists of layers: tests, a client, models with schemas, data builders, configuration and reporting. Tests describe only the scenario and the assertions, the client knows addresses, headers and authentication, and builders give valid data with one field changed. So a change to an endpoint touches one place, not a hundred tests.
API · Automation
One field changed in one endpoint and 140 tests failed. Where is the wrong boundary?
A team writes API tests like this: every test assembles the address, sets the token, builds the body and compares JSON itself. After one field is renamed most of the suite fails, and the cause has to be searched for in every file. This lesson is about the layers of an API automation framework, what each layer knows and what it must not know.
How it works and why. Splitting by responsibility gives every change a single place. What changes for different reasons (an address, a response schema, data, an environment) lives in different layers:
Layer
What it knows
What it must not know
Tests
the scenario, the expected result
addresses, headers, tokens
Endpoint clients
paths, methods, serialization
business assertions
Transport
base URL, headers, authentication, timeouts
specific endpoints
Models and schemas
the shape of requests and responses
how to send them
Data builders
a valid object by default
the test scenario
Configuration
environment, secrets, flags
test code
Reporting
request, response, the reason for a failure
assertion logic
Authentication belongs in the transport: the token is obtained once per run or per worker, cached until it expires and refreshed automatically, and a test calls the client. Reporting must show the method, address, body and response, but mask Authorization and secrets.
Example, before and after. Before: the address, headers and body are scattered over the tests. After: the transport and the endpoint client sit in one place, the data comes from a builder and the test stays a scenario.
exportconst buildOrder = (over: Partial<NewOrder> = {}): NewOrder => ({
sku: 'A-1',
qty: 1,
...over,
});
// the test is only the scenarioconst res = await orders.create(buildOrder({ qty: 0 }));
expect(res.status).toBe(422);
The builder gives an object that is valid by default and changes one field, so the test shows exactly which value is checked. If the server adds a required field, the builder is fixed, not a hundred tests. The OrdersClient holds the path /orders: renaming it changes one line.
Schemas and the contract. Typed models catch mistakes while tests are written, while JSON Schema or a client generated from OpenAPI checks the real response. If a specification exists, it is better to generate types and clients from it than to write them by hand: a mismatch between the specification and the code then becomes a build error. The response is checked against the schema in one place of the transport or a helper, not in every test.
Data and isolation. Every test creates the data it needs through the API (or a fixture) and does not depend on run order: otherwise a parallel run gives flaky failures. Unique values (an email, an order number) are generated by the builder. Cleanup is better done through a delete API or a separate test environment than by relying on a "clean database".
Limits and alternatives. There should be no more layers than the suite needs. For a dozen checks a Postman collection with Newman or the CLI in CI is enough; a framework in code pays off when there are dozens of tests, the logic is complex, and data and authentication need code. A deeply branched hierarchy of base classes and a "universal" client for every case make tests harder to maintain. Contract tests (Pact) and schema checks are kept apart from scenario tests because they answer a different question.
Common mistakes.
The token and address in every test: changing the environment or authentication scheme breaks the whole suite.
Assertions inside the client: a client that throws on 4xx does not allow a negative test to be written.
Shared data between tests: one test depends on what another created, and a parallel run breaks.
Secrets in the report: Authorization in a request log ends up in CI artifacts.
Check yourself
An endpoint client throws on every non-2xx response. What cannot be written?
Answer
Negative tests: checking that the server returns 422 or 404 for an invalid request turns into catching an exception instead of an ordinary status assertion. The client should return the status and the body, and the test decides what counts as an error.
A new required field on the server broke 60 tests. What does that number show?
Answer
The request body is built in the tests themselves rather than in a builder. In a proper structure the builder is fixed, and tests that do not care about the field notice nothing.
Related lessons: "Test design for APIs", "The most critical API bugs".
In an interview.Junior: tests should not know addresses and tokens: that lives in a separate client layer, and the data comes from a builder. Middle/Senior: I split the layers by reason to change: the transport with authentication, endpoint clients, models with schemas (preferably generated from the specification), builders, configuration and reporting with secret masking. Tests stay scenarios, data is independent, and the size of the framework matches the size of the suite: for a small suite a collection in a CLI is enough.