Interview Insights · API Testing
Why Confidence Without APIs Skills Still Fails
Quick summary — API skills
Interviewers enjoy confident candidates, but they hire the ones whose confidence survives the second question. A confident candidate says 'I have tested many REST APIs' clearly and with a smile. That is a good start. Then I ask what they checked apart from the status code, or what 401 and 403 mean, or how they handled an expiring token. If the skill is missing, the confidence turns into vague phrases. The fix is not to sound less confident. It is to build depth in the handful of API topics every interviewer probes.
In this guide you will learn:
- Why API rounds go one level deeper almost immediately
- Status code pairs interviewers use to test real understanding
- HTTP method behaviour including PUT, PATCH and idempotency
- Authentication flows and how tests should handle tokens
- Working REST Assured code that shows depth in a few lines
SECTION 01Status codes: where confident answers break first
Almost every API candidate knows 200, 404 and 500. That is why interviewers do not ask about them. They ask about pairs that sound similar but mean different things: 401 and 403, 400 and 422, 200 and 201, 500 and 503. A confident candidate who has only memorised the common codes tends to say 'both are errors' or 'both mean success', which reveals the gap instantly.
The deeper skill is knowing what each code tells the client to do next. That is what makes a status code assertion meaningful in a test.
| Code pair | Shallow answer | Correct distinction | What your test should check |
|---|---|---|---|
| 401 vs 403 | Both are auth errors | 401: not authenticated. 403: authenticated but not allowed | Missing token gives 401; valid user without role gives 403 |
| 200 vs 201 | Both mean success | 201 means a resource was created, often with a Location header | POST create returns 201 and the new resource ID |
| 400 vs 422 | Both are bad request | 400: malformed request. 422: well-formed but fails validation (API-dependent) | Broken JSON vs invalid email in valid JSON |
| 500 vs 503 | Both are server errors | 500: unexpected failure. 503: temporarily unavailable, may include Retry-After | Retry logic only for 503, not for 500 |
Interviewer: What is the difference between 401 and 403?
Candidate: Both are authentication errors. 401 is
unauthorized and 403 is forbidden, so basically when
the user is not allowed.
Interviewer: So which one would you expect if I send
a valid token for a user who is not an admin, to an
admin-only endpoint?
Candidate: ...401? Or maybe 403. It depends on the API.import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.*;
import org.junit.jupiter.api.Test;
class AdminAccessTest {
static final String BASE = System.getenv("API_BASE");
@Test
void noTokenGives401() {
given().baseUri(BASE)
.when().get("/admin/users")
.then().statusCode(401);
}
@Test
void normalUserGets403() {
String userToken = TokenHelper.loginAs("normal_user");
given().baseUri(BASE)
.auth().oauth2(userToken)
.when().get("/admin/users")
.then().statusCode(403)
.body("error", containsString("permission"));
}
}
The second test is the interesting one. It proves the API knows who you are but refuses the action. A candidate who has written that test will never confuse 401 and 403 again, because they have seen both responses for themselves.
SECTION 02HTTP methods and idempotency: the follow-up nobody prepares
Candidates confidently say GET reads, POST creates, PUT updates and DELETE deletes. The follow-up is usually about behaviour: what happens if the same request is sent twice? That is idempotency. GET, PUT and DELETE are defined as idempotent, so repeating them should leave the server in the same state. POST is not, so two identical POSTs may create two records.
This matters in testing because retries, double clicks and network timeouts all cause repeated requests. A tester who understands idempotency writes tests for duplicates. A tester who does not is surprised by them in production.
| Method | Typical use | Idempotent? | Test idea |
|---|---|---|---|
| GET | Read a resource | Yes (and safe) | Repeated GETs return same data and change nothing |
| POST | Create or trigger an action | No | Send the same order twice: are two orders created? Should they be? |
| PUT | Replace a resource fully | Yes | Send same PUT twice: final state identical; missing fields may be cleared |
| PATCH | Update part of a resource | Not guaranteed | Send a PATCH and check untouched fields stay the same |
@Test
void patchChangesOnlyOneField() {
String id = createUser("Asha", "asha@example.test", "Pune");
given().baseUri(BASE).auth().oauth2(adminToken)
.contentType("application/json")
.body("{\"city\": \"Noida\"}")
.when().patch("/users/" + id)
.then().statusCode(200);
given().baseUri(BASE).auth().oauth2(adminToken)
.when().get("/users/" + id)
.then().statusCode(200)
.body("city", equalTo("Noida"))
.body("name", equalTo("Asha")) // unchanged
.body("email", equalTo("asha@example.test")); // unchanged
}@Test
void sameIdempotencyKeyCreatesOneOrder() {
String key = java.util.UUID.randomUUID().toString();
String body = "{\"productId\": 42, \"qty\": 1}";
String first = given().baseUri(BASE).auth().oauth2(userToken)
.header("Idempotency-Key", key)
.contentType("application/json").body(body)
.when().post("/orders")
.then().statusCode(201)
.extract().path("id").toString();
String second = given().baseUri(BASE).auth().oauth2(userToken)
.header("Idempotency-Key", key)
.contentType("application/json").body(body)
.when().post("/orders")
.then().statusCode(anyOf(is(200), is(201)))
.extract().path("id").toString();
org.junit.jupiter.api.Assertions.assertEquals(first, second);
}
// Only valid if the API supports an Idempotency-Key header.
// Check the API docs first and say so in the interview.
Notice the comment at the end of the duplicate POST test. Idempotency keys are a design choice, not a rule of HTTP. Saying 'this depends on whether the API supports it' is a sign of real knowledge, not uncertainty.
SECTION 03Authentication: the topic that exposes copied frameworks
Many candidates use a framework where authentication is already handled by someone else's helper method. They are confident running tests, but cannot explain how the token is obtained, where it is stored or what happens when it expires. Interviewers know this, so they ask about it on purpose.
You do not need to be a security expert. You need to explain one auth flow you used, how your tests got a token, and how they would behave if the token became invalid during a run.
| Auth type | How it works in brief | How tests usually handle it | Interview probe |
|---|---|---|---|
| API key | Static key sent in a header or query | Read from environment variable, never hard-coded | Where do you keep the key in CI? |
| Basic auth | Base64 of username:password in a header | Use the tool's built-in basic auth helper | Is Base64 encryption? (No, it is encoding) |
| Bearer token (OAuth2/JWT) | Token from login or token endpoint, sent as Authorization header | Fetch once per run, reuse, refresh on expiry | What if the token expires mid-suite? |
| Session cookie | Server sets a cookie after login | Capture the cookie and send it on later calls | How is this different from a bearer token? |
import static io.restassured.RestAssured.given;
public class TokenHelper {
private static String cached;
public static synchronized String adminToken() {
if (cached == null) {
cached = given()
.baseUri(System.getenv("API_BASE"))
.contentType("application/x-www-form-urlencoded")
.formParam("grant_type", "client_credentials")
.formParam("client_id", System.getenv("CLIENT_ID"))
.formParam("client_secret", System.getenv("CLIENT_SECRET"))
.when().post("/oauth/token")
.then().statusCode(200)
.extract().path("access_token");
}
return cached;
}
public static synchronized void reset() {
cached = null; // call when a 401 shows the token expired
}
}"Our tests use the client credentials flow. Before the
first API call, the helper posts the client ID and
secret to the token endpoint and caches the access
token for the run.
The secret is never in the code; it comes from CI
environment variables.
If a call returns 401 because the token expired, the
retry filter resets the cache, gets a fresh token and
retries that call once. If it fails again, the test
fails, because then it is probably a real auth bug,
not an expiry."
The phrase 'retries once, then fails' is important. Retrying forever hides real bugs. Interviewers listen for whether you understand that tests should handle expected situations but still report genuine failures.
SECTION 04A depth check you can run on yourself
Use these three tabs to find where your confidence is ahead of your skill. Answer the self-test out loud, then use the practice plan and the answer frame to close the gaps you find.
Answer each aloud in under 30 seconds. No notes.
1. 401 vs 403, with a request that causes each.
2. 200 vs 201 vs 204: when does an API return each?
3. Which HTTP methods are idempotent? Why does it matter?
4. PUT vs PATCH: what happens to fields you leave out?
5. Where does your test suite get its auth token?
6. What happens if the token expires mid-run?
7. Apart from status code, name three things you
assert on in a response.
8. How do you test that an API rejects invalid input?
Any answer starting with 'basically' or 'it depends'
with no follow-up: mark it as a gap.Use a free practice API that supports GET, POST, PUT,
PATCH and DELETE, or a local mock server.
SESSION 1 Trigger and capture: 200, 201, 204, 400,
401, 404. Save each request and response.
SESSION 2 Write PUT and PATCH tests. Check which
fields survive each.
SESSION 3 Send the same POST twice. Note what happens
and what you think should happen.
SESSION 4 Write a token helper using env variables.
Force an expired token and handle it.
SESSION 5 Explain each session aloud in 2 minutes,
recording yourself.For any API concept question:
1. DEFINE in one sentence
"PATCH updates part of a resource."
2. CONTRAST with its neighbour
"Unlike PUT, which replaces the whole resource."
3. BEHAVIOUR when repeated or failing
"PATCH is not guaranteed to be idempotent."
4. TEST you would write
"I PATCH one field, then GET and check the other
fields did not change."
Four sentences. Confident AND deep.
SECTION 05Habits that keep confidence and skill in step
Confidence is useful. These habits make sure it is backed by something an interviewer can verify.
- Learn codes in pairs — Study 401 with 403, 400 with 422, 200 with 201. Pairs force you to understand the difference, not just the name.
- Trigger every code yourself — For each status code you claim to know, have a saved request that produces it. You will remember the behaviour, not just the label.
- Read the auth code in your project — Even if someone else wrote it, read it line by line until you can explain how tokens are fetched, stored and refreshed.
- Assert beyond status — Practise checking body fields, headers, response time and schema. Interviewers often ask what else you validated.
- Say 'it depends' with a reason — 'It depends on whether the API supports idempotency keys' is strong. 'It depends' with nothing after it is weak.
SECTION 06Interview Q&A — API skills
Q1What is the difference between 401 and 403?
401 means the request is not authenticated, for example no token or an invalid one. 403 means the server knows who you are, but you do not have permission for that action. I test 401 by calling without a token and 403 by calling an admin endpoint with a normal user's valid token.
Q2What is idempotency in REST APIs?
An operation is idempotent if repeating it leaves the server in the same state as doing it once. GET, PUT and DELETE are idempotent by definition; POST is not. I test it by repeating requests and checking the final state, and for POST I check whether duplicates are prevented when the API supports idempotency keys.
Q3What is the difference between PUT and PATCH?
PUT replaces the whole resource with what you send, so fields you leave out may be cleared or reset. PATCH changes only the fields you send. My test sends a PATCH for one field, then does a GET to confirm the other fields are unchanged.
Q4How do you handle authentication in API automation?
I fetch a token once per run using a helper, with credentials from environment variables, and send it as a bearer token. If a call returns 401 due to expiry, the helper refreshes the token and retries once. A second failure fails the test, because it may be a real auth problem.
Q5What do you validate in an API response apart from the status code?
The response body fields and values, the data types and structure against a schema, important headers such as Content-Type or Location, error messages for negative cases, and response time against an agreed limit. For writes, I also check the state with a follow-up GET.
SECTION 07Test yourself — API skills quiz
Five questions. No sign-up.
0 / 5Pick an answer to see why it is right or wrong.
SECTION 08Frequently asked questions
What API testing skills are asked in interviews?
Common topics include HTTP methods, status codes, request and response structure, authentication, assertions beyond status codes, schema validation, negative testing, chaining requests and an automation tool such as REST Assured, Postman or Python requests.
Is Postman enough for API testing jobs?
Postman is a good start and widely used, but many roles also expect code-based automation with a tool like REST Assured or Python requests, integrated into CI. Knowing the concepts deeply matters more than any single tool.
What is the difference between authentication and authorization?
Authentication checks who you are, for example with a token or password. Authorization checks what you are allowed to do. In APIs, failed authentication usually returns 401 and failed authorization usually returns 403.
How do I prepare for an API testing interview?
Learn status codes in pairs, understand idempotency and PUT versus PATCH, practise one authentication flow, and write small automated tests against a practice API. Then explain each concept aloud with an example test.
What is REST Assured used for?
REST Assured is a Java library for testing REST APIs. It lets you send requests and assert on status codes, headers and body values in a readable given-when-then style, and it works with test runners like JUnit or TestNG.
Where can I practise APIs interview questions with expert feedback?
Yes. Uncodemy's API Automation Testing Training Course in Noida (classroom and online) includes live projects, one-to-one mock interviews and resume reviews, so you practise APIs interview questions with trainer feedback before the real interview. You can book a free demo class from this page to see how the sessions work.
SECTION 09Related reads
Classroom & online · Noida
Build API skills that survive follow-ups
Our API Automation Testing Training Course takes you from HTTP basics to REST Assured and Postman automation, with auth, schema validation and CI practice, plus mock rounds that probe your depth.
Talk to a counsellor for current fees- REST Assured & Postman
- Auth and token handling
- Schema & negative testing
- Mock API interviews