Consider a REST API endpoint /users/123 that returns user details if the user exists. The user with ID 123 exists.
What HTTP status code should the server return for a successful GET request to /users/123?
Think about the standard response for a successful data retrieval.
A successful GET request returns 200 OK indicating the resource was found and returned.
You receive this JSON response from a REST API:
{"id": 123, "name": "Alice", "email": "alice@example.com"}Which assertion correctly checks that the name field is Alice?
Remember how to access JSON data from a response object.
Option A correctly calls response.json() to parse JSON and compares the name field. Option A and D are invalid because response is not a dict. Option A uses assignment = instead of comparison ==.
You want to test a REST API that supports multiple versions. Which HTTP header is the best practice to specify the API version in your request?
Think about which header tells the server what format or version the client expects.
The Accept header is used to specify the media type and version the client expects, e.g., application/vnd.api.v2+json. Content-Type describes the request body format, Authorization is for credentials, and User-Agent identifies the client software.
Test code sends this JSON payload in a POST request:
{"username": "bob", "password": 12345}The API expects the password as a string, but the test fails with 400 Bad Request. Why?
Check the data types in the JSON payload.
The API expects the password as a string, but the test sends it as a number (12345). This type mismatch causes the server to reject the request with 400 Bad Request.
You want to write automated tests for REST APIs that require preparing test data before tests and cleaning up after. Which feature of a test framework best supports this?
Think about how to prepare and clean test environments automatically.
Fixtures or setup/teardown methods allow you to prepare test data and environment before tests run and clean up after tests finish, which is essential for reliable REST API testing.