API testing interview questions on REST, HTTP methods and status codes, authentication, REST Assured, Postman, schema and contract testing, and real-time scenarios.
50 questions17 Beginner21 Intermediate12 Advanced
Interactive Practice Sandbox
Practice API Testing Online with Zero Setup
Apply these interview concepts directly in your browser. Solve 64+ interactive API automation challenges in Java (REST Assured), Python (requests), or Playwright against real practice endpoints.
API testing validates the business logic, data, security and performance of services directly at the request/response layer, without a UI. It is faster and more stable than UI testing and catches defects earlier in the pipeline.
Key points
Sits in the middle of the test pyramid: more API tests than UI tests
Validates status codes, headers, response body, schema and response time
Can run before the UI is built (shift-left)
Less flaky because there is no rendering or browser timing
Interview tip: Interviewers often follow up with: what would you test at API level vs UI level? Answer: business rules and data at API, user flows and rendering at UI.
API testing validates the business logic, data, security and performance of services directly at the request/response layer, without a UI. It is faster and more stable than UI testing and catches defects earlier in the pipeline.
Answer
REST is an architectural style that uses HTTP methods on resources and usually exchanges JSON, while SOAP is a strict XML-based protocol with a WSDL contract and envelope. REST is lighter and dominant for modern web APIs; SOAP is still found in banking and legacy enterprise systems.
SOAP: XML only, WSDL contract, WS-Security, built-in error faults
REST uses HTTP status codes; SOAP usually returns 200 with a Fault element
GraphQL and gRPC are other common styles in 2026
REST is an architectural style that uses HTTP methods on resources and usually exchanges JSON, while SOAP is a strict XML-based protocol with a WSDL contract and envelope. REST is lighter and dominant for modern web APIs; SOAP is still found in banking and legacy enterprise systems.
Answer
GET reads, POST creates, PUT replaces, PATCH partially updates and DELETE removes a resource. GET, PUT, DELETE, HEAD and OPTIONS are idempotent, meaning repeating the same call leaves the server in the same state; POST and PATCH are not guaranteed to be.
Key points
Safe methods (GET, HEAD, OPTIONS) should not change server state
PUT sends the full resource; PATCH sends only changed fields
Idempotent does not mean same response: a second DELETE may return 404
Test idempotency by sending the same request twice and checking DB state
Interview tip: Common mistake: saying POST is idempotent. Mention idempotency keys used by payment APIs to make POST retries safe.
GET reads, POST creates, PUT replaces, PATCH partially updates and DELETE removes a resource. GET, PUT, DELETE, HEAD and OPTIONS are idempotent, meaning repeating the same call leaves the server in the same state; POST and PATCH are not guaranteed to be.
Answer
2xx means success (200 OK, 201 Created, 204 No Content), 3xx is redirection, 4xx is a client error (400, 401, 403, 404, 409, 422, 429) and 5xx is a server error (500, 502, 503, 504).
Key points
401 = not authenticated; 403 = authenticated but not allowed
409 Conflict for duplicates; 422 for semantically invalid payloads
429 Too Many Requests for rate limiting
A 5xx on bad input is a bug: the API should return a 4xx
Interview tip: Be ready to explain 401 vs 403 clearly; it is asked in almost every API interview.
2xx means success (200 OK, 201 Created, 204 No Content), 3xx is redirection, 4xx is a client error (400, 401, 403, 404, 409, 422, 429) and 5xx is a server error (500, 502, 503, 504).
Answer
Path parameters identify a specific resource and are part of the URL path, like /users/42. Query parameters filter, sort or paginate a collection and come after the ?, like /users?role=admin&page=2.
Key points
Path params are usually mandatory; query params are optional
Test missing, invalid type, and boundary values for both
Check URL encoding of special characters in query values
http
GET /api/users/42 # path param
GET /api/users?role=admin&page=2 # query params
GET /api/orders/42/items?sort=price # both
Path parameters identify a specific resource and are part of the URL path, like /users/42. Query parameters filter, sort or paginate a collection and come after the ?, like /users?role=admin&page=2.
Answer
I validate the status code, response time, headers such as Content-Type, the body values and data types, the JSON schema, and the side effect in the database or downstream systems.
Body: field values, types, mandatory fields, no sensitive data leaked
Schema validation catches contract drift
Negative cases: error message and error code format
I validate the status code, response time, headers such as Content-Type, the body values and data types, the JSON schema, and the side effect in the database or downstream systems.
Answer
I organise requests into collections, use environments and variables for base URLs and tokens, write assertions in the Tests (post-response) script tab, and run collections in CI with Newman or the Postman CLI.
Key points
Environment variables switch between dev, QA and staging
Pre-request scripts generate tokens or dynamic data
pm.environment.set chains values between requests
Data-driven runs with CSV/JSON files in the Collection Runner
javascript
pm.test("Status is 201", () => {
pm.response.to.have.status(201);
});
pm.test("Has user id", () => {
const body = pm.response.json();
pm.expect(body.id).to.be.a("number");
pm.environment.set("userId", body.id);
});
I organise requests into collections, use environments and variables for base URLs and tokens, write assertions in the Tests (post-response) script tab, and run collections in CI with Newman or the Postman CLI.
Answer
I have tested Basic auth, API keys, Bearer tokens such as JWT, and OAuth 2.0 flows like client credentials and authorization code with PKCE. For each I test valid, missing, expired, malformed and insufficient-scope tokens.
Key points
Authentication = who you are; authorization = what you can do
JWT has header, payload and signature; check expiry (exp) and claims
OAuth 2.0 client credentials is common for service-to-service tests
Never hard-code secrets; load them from CI secrets or a vault
Interview tip: Follow-up: how do you handle token expiry in a long suite? Fetch the token once, cache it, and refresh it when it is near expiry.
I have tested Basic auth, API keys, Bearer tokens such as JWT, and OAuth 2.0 flows like client credentials and authorization code with PKCE. For each I test valid, missing, expired, malformed and insufficient-scope tokens.
Answer
REST Assured uses a given/when/then BDD style: given sets headers, auth and body, when sends the request, and then asserts the status code and body using Hamcrest matchers.
Key points
Prefer POJOs or Maps serialized by Jackson over raw JSON strings
Use RequestSpecification/ResponseSpecification for reuse
extract().path("id") to chain values into the next request
REST Assured uses a given/when/then BDD style: given sets headers, auth and body, when sends the request, and then asserts the status code and body using Hamcrest matchers.
Answer
I keep a base RequestSpecification with base URI, auth and logging, service classes per resource that wrap endpoints, POJOs for request and response payloads, config per environment, and TestNG or JUnit for execution and reporting.
Lombok + Jackson for POJOs; builder pattern for test data
Allure filter for request/response logs in reports
Parallel execution with thread-safe tokens and data
java
public class Specs {
public static RequestSpecification base() {
return new RequestSpecBuilder()
.setBaseUri(Config.get("baseUrl"))
.setContentType(ContentType.JSON)
.addHeader("Authorization", "Bearer " + TokenManager.get())
.addFilter(new AllureRestAssured())
.build();
}
}
// usage
User user = given().spec(Specs.base()).get("/users/1").as(User.class);
I keep a base RequestSpecification with base URI, auth and logging, service classes per resource that wrap endpoints, POJOs for request and response payloads, config per environment, and TestNG or JUnit for execution and reporting.
Answer
I keep a JSON Schema file describing required fields, types and formats, and assert the response against it. In REST Assured I use the json-schema-validator module's matchesJsonSchemaInClasspath.
Key points
Catches removed fields, type changes and nullability changes
Use additionalProperties: false carefully; it can make tests brittle
Generate schemas from the OpenAPI spec to stay in sync
I keep a JSON Schema file describing required fields, types and formats, and assert the response against it. In REST Assured I use the json-schema-validator module's matchesJsonSchemaInClasspath.
Answer
Contract testing verifies that a consumer and provider agree on the request and response format, using a shared contract, without deploying both services together. Consumer-driven tools like Pact record consumer expectations and replay them against the provider in its own pipeline.
Key points
Integration tests need both services running; contract tests do not
Pact: consumer test generates a pact file, provider verifies it
Pact Broker / PactFlow shares contracts and can-i-deploy checks
Provider-driven alternative: validate against the OpenAPI spec
Interview tip: Real-time note: contract tests are most valuable in microservices where teams deploy independently and break each other with field renames.
Contract testing verifies that a consumer and provider agree on the request and response format, using a shared contract, without deploying both services together. Consumer-driven tools like Pact record consumer expectations and replay them against the provider in its own pipeline.
Answer
Playwright provides the request fixture and APIRequestContext to send HTTP calls in the same test runner as UI tests. I use it for pure API tests and to set up data or log in through the API before a UI test.
Key points
Set baseURL and extraHTTPHeaders in playwright.config
request.storageState() can save auth for UI tests
page.route() mocks APIs; request fixture calls real APIs
Playwright provides the request fixture and APIRequestContext to send HTTP calls in the same test runner as UI tests. I use it for pure API tests and to set up data or log in through the API before a UI test.
Answer
I would send missing mandatory fields, wrong data types, boundary and overlong values, invalid formats like a bad email, duplicate records, invalid or missing auth, an unsupported Content-Type, and malformed JSON, and expect clear 4xx responses with no record created.
Key points
Expect 400/422 for validation, 401/403 for auth, 409 for duplicate, 415 for media type
Verify no partial data is saved in the database
Check error messages do not leak stack traces
Try injection strings in text fields
Interview tip: Interviewers like hearing that you verify the DB side effect, not just the status code.
I would send missing mandatory fields, wrong data types, boundary and overlong values, invalid formats like a bad email, duplicate records, invalid or missing auth, an unsupported Content-Type, and malformed JSON, and expect clear 4xx responses with no record created.
Answer
I chain requests by extracting values like orderId from one response and passing them into the next, asserting each step and the final state. Test data is created in setup and cleaned up after, so the flow is independent and repeatable.
Key points
Extract ids with jsonPath / extract().path()
Handle async steps by polling status with a timeout instead of fixed sleeps
Validate the final state in the DB or via a GET
Mock third-party payment gateways in lower environments
I chain requests by extracting values like orderId from one response and passing them into the next, asserting each step and the final state. Test data is created in setup and cleaned up after, so the flow is independent and repeatable.