Interview prep · 227 questions

API testing interview questions

Updated

The API-testing questions interviewers actually ask — HTTP and status codes, authentication, schema validation, the negative cases that separate juniors from seniors — each with the short answer to say out loud, the follow-up, and the trap. Skim the previews; open what you need.

16 questions

What is API testing, and why test at the API layer at all?

API Fundamentalsjuniormid

API testing checks the service layer directly — you send a request and assert on the response, without a browser. You verify status, body, headers and behaviour where the logic actually lives.

API testing checks the service layer directly — you send a request and assert on the response, without a browser. You verify status, body, headers and behaviour where the logic actually lives.

You test here because it's faster, more stable and closer to the bug than the UI. A broken business rule shows up in the API response long before it surfaces as a mislabelled button, and an API test doesn't flake on a slow render.

Real-world example

A discount rule that only failed for carts over $500 was invisible in UI tests — the total looked plausible. One API call with a $600 cart returned the wrong total, caught in seconds.

Key points
  • Test the service directly: request in, assert on the response
  • Faster and less flaky than UI — no browser, no render waits
  • Catches broken logic at the layer where it lives
They'll ask next · tap one for the answer
The trap

Don't say "API testing replaces UI testing" — they cover different failure modes. Saying one removes the need for the other reads as junior.

Copy link

What's the difference between API testing and unit testing?

API Fundamentalsjuniormid

A unit test checks one function in isolation, usually with everything around it mocked — it proves the code unit is correct.

A unit test checks one function in isolation, usually with everything around it mocked — it proves the code unit is correct. An API test hits a running service over HTTP and checks the whole request-to-response path: routing, serialisation, auth, the database, the lot.

Unit tests are the developer's; API tests are often yours. They overlap in intent but not in scope — a passing unit test says the function works; a passing API test says the deployed endpoint works.

Key points
  • Unit: one function, isolated, mocked dependencies
  • API: the running service end to end, over HTTP
  • Both can pass while the other fails — different scope
They'll ask next · tap one for the answer
Copy link

Walk me through the main HTTP methods and what each is for.

HTTP & Status Codesjunior

GET reads a resource and changes nothing. POST creates a new one. PUT replaces a resource wholesale. PATCH updates part of it. DELETE removes it.

GET reads a resource and changes nothing. POST creates a new one. PUT replaces a resource wholesale. PATCH updates part of it. DELETE removes it.

The distinction interviewers listen for is safety and idempotency: GET is safe (no side effects); GET, PUT and DELETE are idempotent (same request twice = same end state); POST is neither — call it twice and you may create two resources.

Key points
  • GET read · POST create · PUT replace · PATCH partial-update · DELETE remove
  • Safe = no side effects (GET)
  • Idempotent = repeatable with the same end state (GET, PUT, DELETE)
  • POST is neither — double-submit creates duplicates
They'll ask next · tap one for the answer
Copy link

What do the HTTP status code families mean?

HTTP & Status Codesjunior

2xx succeeded — 200 OK, 201 Created, 204 No Content. 3xx redirect. 4xx the client's fault — 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found, 409 conflict, 422 unprocessable.

2xx succeeded — 200 OK, 201 Created, 204 No Content. 3xx redirect. 4xx the client's fault — 400 bad request, 401 unauthenticated, 403 forbidden, 404 not found, 409 conflict, 422 unprocessable. 5xx the server's fault — 500 internal error, 503 unavailable.

The line that matters in an interview: 401 means "I don't know who you are", 403 means "I know who you are and you can't". Mixing those up is a real, common API bug you should be testing for.

Key points
  • 2xx success · 3xx redirect · 4xx client error · 5xx server error
  • 401 = not authenticated; 403 = authenticated but not allowed
  • 201 for create, 204 for a successful delete with no body
They'll ask next · tap one for the answer
The trap

Confusing 401 and 403 is the classic slip. If you blur them, the interviewer assumes you've never actually debugged an auth failure.

Copy link

What's the difference between PUT and PATCH, and how would you test it?

HTTP & Status Codesmid

PUT replaces the whole resource — whatever you don't send, the server may blank out. PATCH updates only the fields you send and leaves the rest alone.

PUT replaces the whole resource — whatever you don't send, the server may blank out. PATCH updates only the fields you send and leaves the rest alone.

The test that catches the real bug: PATCH a single field, then GET the resource and assert every OTHER field is unchanged. Teams routinely implement PATCH as a disguised PUT, silently nulling fields the client didn't include — and it only shows up when a user loses data.

Real-world example

A profile PATCH that updated displayName was quietly wiping bio because the handler rebuilt the whole record. Nobody noticed until a user's bio vanished after they changed their name.

Key points
  • PUT = full replace; PATCH = partial update
  • Key test: PATCH one field, GET, assert the others survived
  • 'PATCH that behaves like PUT' is a common, data-losing bug
They'll ask next · tap one for the answer
Copy link

What makes an API RESTful?

API Fundamentalsmid

Resources addressed by URL (/orders/42), acted on with HTTP methods, communicating via representations (usually JSON), statelessly — every request carries what the server needs, nothing is remembered…

Resources addressed by URL (/orders/42), acted on with HTTP methods, communicating via representations (usually JSON), statelessly — every request carries what the server needs, nothing is remembered between calls.

In practice most "REST" APIs are pragmatic, not textbook. What matters for testing is the statelessness: if an endpoint depends on hidden server-side session state, that's your bug hunting ground — replay a request in isolation and see if it still works.

Key points
  • Resources as URLs, HTTP methods as verbs, JSON representations
  • Stateless: each request is self-contained
  • Statelessness is a test lever — replay requests in isolation
They'll ask next · tap one for the answer
Copy link

How do you test authentication — API keys, Bearer tokens, OAuth2?

Authenticationmidsenior

First get a valid credential the way a real client does, then prove the endpoint enforces it. For a Bearer/JWT flow: obtain a token, send it in the Authorization header, and assert the happy path…

First get a valid credential the way a real client does, then prove the endpoint enforces it. For a Bearer/JWT flow: obtain a token, send it in the Authorization header, and assert the happy path works.

Then test the enforcement, which is where the bugs are: no token → 401, malformed token → 401, expired token → 401, valid token but wrong permissions → 403, and another user's token → they can't reach your data. The negative cases are the test, not the happy path.

Real-world example

An endpoint accepted any well-formed JWT without checking the signature — a token from a different environment worked in production. Only a 'tampered token' negative test caught it.

Key points
  • Get a real credential, then assert enforcement — not just the happy path
  • Cover: no token, malformed, expired, wrong scope (403), other user's token
  • OAuth2: automate at least one real token exchange, don't hardcode a stale one
They'll ask next · tap one for the answer
The trap

Only testing the happy path ("I sent a valid token and got 200") misses the entire point. Auth testing IS the negative cases.

Copy link

Beyond the status code, what do you actually assert in an API response?

Response Validationmid

The status code is table stakes. Then: the body's structure (the fields you depend on exist, with the right types), the values (the ones the request should have changed), key headers (content-type,…

The status code is table stakes. Then: the body's structure (the fields you depend on exist, with the right types), the values (the ones the request should have changed), key headers (content-type, cache, rate-limit), and response time if it's on a budget.

A 200 with a broken body is the failure a lazy test misses. Asserting status == 200 and stopping is how a green suite ships a null where a customer name should be.

Key points
  • Structure (fields + types), values, headers, timing — not just status
  • A 200 with a wrong or null body is the bug shallow tests miss
  • Assert the specific values your request should have changed
They'll ask next · tap one for the answer
The trap

"I check the status is 200" as a complete answer. Interviewers wait for what else — if nothing follows, the answer stops there.

Copy link

How do you validate a response schema, and why bother if the values look right?

Response Validationmidsenior

You assert the response matches a defined shape — field names, types, what's required, what's nullable — with a JSON Schema validator or a typed model (pydantic, a POJO, a Zod schema).

You assert the response matches a defined shape — field names, types, what's required, what's nullable — with a JSON Schema validator or a typed model (pydantic, a POJO, a Zod schema). One assertion covers the whole structure.

You bother because value checks and schema checks catch different bugs. Your value test asserts price == 41.98; it says nothing about the day price starts arriving as a string, or a required field silently disappears. The schema is your early warning for contract drift.

Real-world example

A backend changed price from a number to a string ("41.98") in a refactor. Every value assertion still passed after a cast; the schema check failed instantly and named the field.

Key points
  • Validate shape: field names, types, required vs nullable
  • Use a schema validator or a typed model, not hand-written field checks
  • Catches contract drift that value assertions sail past
They'll ask next · tap one for the answer
Copy link

What negative and edge cases would you test on a single endpoint?

Negative Testingmid

Take the happy path apart: missing required fields, wrong types, empty and null values, boundary values (0, negative, max length, one over), malformed JSON, extra unexpected fields, and duplicate…

Take the happy path apart: missing required fields, wrong types, empty and null values, boundary values (0, negative, max length, one over), malformed JSON, extra unexpected fields, and duplicate submissions.

Then the ones people forget: SQL/script-looking input in string fields, a huge payload, wrong content-type, and unauthorised access to someone else's resource. The happy path is one test; the interesting coverage is everything the endpoint should reject cleanly — with the right 4xx, not a 500.

Key points
  • Missing/wrong-type/null/boundary inputs, malformed JSON, extra fields
  • Duplicate submit, oversized payload, wrong content-type
  • Rejections should be a clean 4xx — a 500 on bad input is itself a bug
They'll ask next · tap one for the answer
Copy link

How do you handle test data and state across API tests?

API Automationsenior

Each test owns its data. Create what you need in setup (via the API or a seed), use it, and clean it up in teardown — so tests don't depend on a shared record another test might change or delete.

Each test owns its data. Create what you need in setup (via the API or a seed), use it, and clean it up in teardown — so tests don't depend on a shared record another test might change or delete.

The anti-pattern is tests that assume 'user 42 exists' or run in a fixed order. Those pass locally and fail in CI the moment they run in parallel or someone edits the seed. Self-contained data is what makes an API suite safe to run parallel and repeatable.

Real-world example

A suite that shared one 'test order' broke the day it ran in parallel — one test marked it shipped while another asserted it was pending. Giving each test its own order via setup fixed it for good.

Key points
  • Each test creates and tears down its own data
  • No shared records, no order dependence — the CI/parallel killers
  • Seed through the API or DB in setup, clean up after
They'll ask next · tap one for the answer
Copy link

Postman or code (REST Assured, requests) — when do you reach for each?

API Automationmid

Postman for exploring, one-off checks, and sharing a collection with people who don't code — it's fast to poke at an API and see what it does.

Postman for exploring, one-off checks, and sharing a collection with people who don't code — it's fast to poke at an API and see what it does. Code (REST Assured, Python requests + pytest) for anything that has to run in CI, share setup, loop over data, or live beside the rest of the automation.

The honest interview answer: start in Postman to understand the API, then rebuild the checks in code once they're worth keeping. Postman collections in CI via Newman exist, but a real framework outgrows them.

Key points
  • Postman: explore, one-offs, share with non-coders
  • Code: CI, shared setup, data-driven, lives with the framework
  • Common flow: explore in Postman → rebuild as code to keep
They'll ask next · tap one for the answer
Copy link

How would you structure an API test automation framework?

API Automationsenior

Layer it. A thin client/service layer wraps the HTTP calls (one place per endpoint, so a URL change is one edit). Tests call those methods and assert — they never build raw requests inline.

Layer it. A thin client/service layer wraps the HTTP calls (one place per endpoint, so a URL change is one edit). Tests call those methods and assert — they never build raw requests inline. Config (base URLs, credentials) comes from the environment, not hardcoded. Data setup/teardown is in fixtures. Schemas live in one place and are reused.

The test reads like intent — createOrder(); assertStatus(201); assertSchema(order) — and the HTTP mechanics hide behind it. That separation is what lets the suite survive an API that keeps changing.

Key points
  • Service layer wraps HTTP — endpoints defined once
  • Config and secrets from env; data in fixtures; schemas reused
  • Tests express intent, not raw requests
They'll ask next · tap one for the answer
Copy link

How do you test pagination and rate limiting?

Negative Testingsenior

Pagination: assert the page size is honoured, the cursor/offset advances without repeating or skipping items, the last page ends cleanly, and totals are consistent while data is stable.

Pagination: assert the page size is honoured, the cursor/offset advances without repeating or skipping items, the last page ends cleanly, and totals are consistent while data is stable. The classic bug is items shifting between pages when the underlying list changes mid-scan.

Rate limiting: send requests past the limit and assert you get 429 (not 500), that the Retry-After/limit headers are correct, and that the counter resets when it should. And check the limit is per the right key — per user, not global, or one noisy client starves everyone.

Key points
  • Pagination: page size honoured, no repeats/skips, clean last page
  • Rate limit: 429 not 500, correct Retry-After header, proper reset
  • Verify the limit is scoped per-user, not global
They'll ask next · tap one for the answer
Copy link

How do you test an API with no documentation?

API Fundamentalssenior

Explore first, document as you go. Watch the app's network traffic to see real requests, or read the code if you can.

Explore first, document as you go. Watch the app's network traffic to see real requests, or read the code if you can. For each endpoint, map the method, required and optional params, auth, and the response shape by making calls and observing — building a mini-spec from what you find.

Then turn that spec into tests: the happy path, the negative cases, the schema you just reverse-engineered. The write-up you produce is itself valuable — you've documented an undocumented API, which the team probably needed anyway.

Key points
  • Observe real traffic / read code to map endpoints
  • Build a mini-spec: method, params, auth, response shape
  • Turn the spec into tests — and hand back the documentation
They'll ask next · tap one for the answer
Copy link

Walk me through testing a POST that creates a resource, end to end.

API Automationmid

Send the POST with a valid body, assert 201 and that the response includes the new id and echoes the data.

Send the POST with a valid body, assert 201 and that the response includes the new id and echoes the data. Then GET that id and assert the resource actually persisted with the right values — creation isn't proven until you can read it back.

Then the edges: POST the same thing again (duplicate — does it 409 or create a second?), POST with a missing required field (400/422), and clean up the created resource in teardown. The round-trip plus the negatives is the full test; asserting only the 201 is half of it.

Real-world example

An endpoint returned 201 and a shiny id, but a bug meant the record never hit the database. Only the follow-up GET — which 404'd — proved the 'successful' create was a lie.

Key points
  • POST → assert 201 + id, then GET the id to prove it persisted
  • Test duplicate create (409 vs second copy) and missing fields (4xx)
  • Clean up in teardown; a 201 alone doesn't prove creation
They'll ask next · tap one for the answer
The trap

Stopping at 'assert 201' skips the proof of persistence. The GET-after-POST round-trip is what separates a real API test from a shallow one.

Copy link
They'll ask next