300-435 · Question #14
A developer is writing an application that uses a REST API and the application requires a valid response from the API. Which element of the response is used in the conditional check?
The correct answer is B. Status code. To determine if a REST API call received a valid response, the HTTP status code is the primary element used in conditional checks, as it explicitly indicates the success or failure of the request.
Question
Exhibit
Options
- AURL
- BStatus code
- CLink
- DBody
- EHeaders
How the community answered
(42 responses)- A2% (1)
- B86% (36)
- C7% (3)
- D5% (2)
Why each option
To determine if a REST API call received a valid response, the HTTP status code is the primary element used in conditional checks, as it explicitly indicates the success or failure of the request.
The URL is part of the request, not the response, and is not used to check the validity of the API response itself.
The HTTP status code (e.g., 200 OK, 201 Created, 404 Not Found, 500 Internal Server Error) is the standard and most reliable element in a REST API response to determine the success or failure of a request. Developers use conditional checks on these codes to guide application logic and handle various outcomes.
Links (often found in the response body or headers for HATEOAS) provide navigation to related resources but do not, by themselves, indicate the validity or success of the current request.
The response body contains the data returned by the API but does not inherently signal the success or failure of the operation; a successful request might return an empty body, and an error might return an error message in the body.
Headers contain metadata about the response (e.g., content type, caching instructions) but the primary indicator of the request's success or failure is the status code.
Concept tested: REST API response status codes
Source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
Topics
Community Discussion
No community discussion yet for this question.
