API Testing with Postman: Interview Questions and Answers
1. Postman Basics
Q: What is Postman, and why is it used for API testing?
A: Postman is a popular API testing tool that allows users to design, test, and document APIs
efficiently. It is used to validate API functionality, performance, and security.
Q: How do you create and send a request in Postman?
A: To create and send a request in Postman:
1. Open Postman and click 'New' > 'Request'.
2. Enter the request name and save it in a collection.
3. Select the HTTP method (GET, POST, etc.).
4. Enter the API URL.
5. Configure headers, params, or body as needed.
6. Click 'Send' to execute the request.
Q: What are the different HTTP methods (GET, POST, PUT, DELETE, etc.), and when are they used?
A: GET: Retrieve data.
POST: Submit data to the server.
PUT: Update existing data.
DELETE: Remove data.
HEAD, OPTIONS, PATCH: Other methods for specific use cases.
Q: Explain the difference between Params, Headers, and Body in a Postman request.
A: Params: Used for query parameters in the URL.
Headers: Contain metadata like content type or authorization.
Body: Holds the data to be sent to the API (e.g., JSON payload).
Q: How do you handle authentication in Postman?
A: Postman supports multiple authentication methods, including Basic Auth, OAuth, API Keys, and
Bearer Tokens. You can set these under the 'Authorization' tab in the request settings.
Q: What is the purpose of a Postman Collection?
A: A Postman Collection is a group of API requests organized into folders. It is used to manage
related APIs, save configurations, and execute them as a workflow.
2. Practical Usage
Q: How do you test an API with query parameters in Postman?
A: Add key-value pairs in the 'Params' tab. Postman appends them to the API URL automatically.
Q: What steps would you take to test an API that requires a token?
A: 1. Authenticate and obtain the token from the API.
2. Add the token in the 'Authorization' tab or 'Headers'.
3. Send the request and verify the response.
Q: How can you validate the response code, headers, and body in Postman?
A: Postman provides response validation options in the 'Tests' tab. You can write JavaScript
assertions for status codes, headers, and body content.
Q: Explain how to use environment variables and global variables in Postman.
A: Environment variables are specific to an environment (e.g., dev, staging). Global variables are
accessible across all environments. Use the '{{variable_name}}' syntax in requests.
Q: What is a pre-request script, and when would you use it?
A: A pre-request script is JavaScript code executed before the request. It is used to set dynamic
variables, generate tokens, or modify the request dynamically.
Q: How do you create a workflow using Postman Collections?
A: Postman Collections allow you to chain requests by using variables and test scripts. You can
control the execution order and add conditions or loops.