PrepPilotPractise free

API Testing interview questions

REST testing, contracts, auth, tools

17 questions · POST · updated November 2026

Practise these as flashcards. One or two lines each; the ones you miss come back first.

Start free

Core questions

What status codes should you check when testing a REST API?

I check for standard status codes like 200 for success, 201 for resource creation, 400 for bad requests, 401 for unauthorized, 404 for not found, and 500 for server errors. Each endpoint should return the appropriate code for the operation and error scenario.

How do you validate the schema of an API response?

I use schema validation tools or libraries to compare the response body against a defined JSON schema. This ensures all required fields are present, types are correct, and no unexpected fields are included.

Why is it important to test API headers?

Headers contain important metadata like content type, caching, and authentication info. Testing headers ensures the API follows protocol standards and clients can interpret responses correctly.

What is negative testing in API validation?

Negative testing involves sending invalid or unexpected inputs to the API to check if it handles errors gracefully. It helps ensure the API returns proper error codes and messages without exposing sensitive information.

Intermediate questions

How do you automate API tests using Postman?

I create collections in Postman, define requests, and add test scripts to validate status codes, response bodies, and headers. Collections can be run in the Postman app or via Newman in CI pipelines for automation.

Describe how REST Assured is used for API testing in Java.

REST Assured allows me to write fluent Java tests for APIs. I set up requests, define expectations for status codes and response bodies, and integrate these tests with JUnit or TestNG for automated runs in CI.

How do you handle authentication tokens in automated API tests?

I automate token retrieval by calling the auth endpoint in setup steps, storing the token, and passing it in the Authorization header for subsequent requests. This avoids hardcoding credentials and keeps tests maintainable.

What is contract testing and how does Pact help?

Contract testing verifies that the API provider and consumer agree on the data structure and endpoints. Pact lets me define contracts as code, run them against providers, and catch breaking changes before deployment.

How do you manage test data for API tests?

I use fixtures or seed scripts to set up known data before tests, and clean up afterwards to avoid pollution. For external dependencies, I mock responses to ensure tests are repeatable and not affected by real data changes.

How do you test error handling in an API?

I send invalid requests, like missing required fields or unauthorized access, and check if the API returns the correct status code and error message. This helps ensure the API doesn't fail silently or expose sensitive details.

What are some basic security checks you include in API tests?

I test for unauthorized access, input validation, and proper error handling. For example, I try accessing protected endpoints without a token, check for SQL injection vulnerabilities, and verify sensitive data isn't exposed.

How do you validate headers like Content-Type and Cache-Control in API tests?

I add assertions in my test scripts to check that headers like Content-Type are set correctly, and Cache-Control is present when needed. This ensures clients can process responses and caching works as intended.

What are the advantages of using pytest with requests for API testing?

See the answer in the app, free

Senior questions

How would you design a test suite to cover both functional and security aspects of a REST API?

See the answer in the app, free

How do you ensure your API tests are reliable and not flaky due to external dependencies?

See the answer in the app, free

How do you handle versioning and backward compatibility in API contract testing?

See the answer in the app, free

Describe a scenario where negative testing revealed a security vulnerability.

See the answer in the app, free

More Quality & Security topics