Explore essential concepts of REST API testing and request validation using Postman. Assess your understanding of HTTP methods, responses, status codes, and effective test automation techniques for efficient API development and debugging.
Which HTTP method should you use in Postman to retrieve resource data from a REST API endpoint, such as getting a list of users?
Explanation: The GET method is used to request data from a server without making any changes to the resource. POST is meant for creating resources, while PUT is used for updating existing data. The option 'SEND' is not an HTTP method, and thus not valid for this context.
When testing a successful API request in Postman, what HTTP status code should you expect in response to a correct GET request for data?
Explanation: A '200' status code indicates a successful request and is the standard response for a successful GET operation. '404' means the resource was not found, and '500' signals a server-side error. '201' represents successful creation, usually from a POST request, not a simple GET.
If an API requires an authentication token, which Postman feature allows you to conveniently add it to all requests in a collection?
Explanation: The Authorization tab in Postman collections is designed for adding authentication tokens or credentials that can be inherited by requests in the collection. The Tests tab is used for scripting tests; the Headers panel allows manual entry but lacks centralized management. The Body tab is for request payloads and is not involved in authorization.
Which Postman test script would best check if the JSON response from an API contains a key named 'status' with the value 'active'?
Explanation: The statement 'pm.expect(jsonData.status).to.eql('active');' is the correct JavaScript code used in Postman to assert the value of a specific JSON key. The other options are either incorrect syntax, not valid in this context, or completely unrelated to Postman scripting.
How can you store a value from an API response in Postman and use it in the next request, such as saving an 'id' for reuse?
Explanation: Setting the value as an environment variable allows for automatic storage and reuse across requests, supporting dynamic workflows. Copying and pasting is manual and error-prone. 'Persist Variables' is not a function for capturing runtime values, and placing data in headers is incorrect for storing response variables.