200-901 Question 87
Select 3You are developing a Python application that integrates with a REST API to retrieve user data. The API reference documentation provides the following details for the endpoint:
GET /users/{user_id}
- Description: Retrieve information about a specific user by their ID.
- Query Parameters:
fields(optional): A comma-separated list of fields to include in the response.
- Response Codes:
200: Successful response.404: User not found.400: Invalid request.
What steps should you take to successfully retrieve a user's name and email from this API endpoint?
- A
Pass the user ID in the URL path and include
fields=name,emailas a query parameter. - B
Use a POST request to the
/users/{user_id}endpoint withfields=name,emailin the request body. - C
Send a GET request to
/users/{user_id}and include a query parameterfields=name,email. - D
Ensure proper error handling for HTTP status codes
404and400in your application. - E
Include the user ID in the request body and specify
fields=name,emailin the query parameters.
Show answer and explanation
Correct answers: A, C, D
Explanation
To successfully retrieve the user's name and email, you need to follow the API documentation guidelines. This includes passing the user ID in the URL path, using the fields query parameter to specify the required fields, and making a GET request. Additionally, proper error handling for potential HTTP status codes (404 and 400) ensures the application can handle edge cases and failures gracefully.
- A. Correct.
Correct: The user ID should be passed in the URL path as specified in the API documentation, and the
fieldsquery parameter should be used to specify the required fields. - B. Incorrect.
Incorrect: The API documentation specifies that this endpoint requires a GET request, not a POST request.
- C. Correct.
Correct: A GET request with the appropriate query parameter (
fields=name,email) is required to retrieve the specified fields. - D. Correct.
Correct: Proper error handling for HTTP status codes
404(User not found) and400(Invalid request) is crucial for building a robust application. - E. Incorrect.
Incorrect: The API documentation does not mention including the user ID in the request body; it should be passed in the URL path.