Google Professional Cloud Developer Question 445
Single answerGoogle Cloud PlatformYou are designing a REST API for a movie streaming service hosted on Google Cloud. The API allows users to query movie details using a GET /movies endpoint. For security and performance reasons, you want to restrict the data returned to only include specific fields requested by the client (e.g., title, genre). How can you implement this requirement effectively using Google Cloud's resources?
- A
Use a query parameter to specify the fields to return and implement field filtering in your API code.
- B
Configure a Cloud Storage bucket to automatically filter fields based on the client request.
- C
Enable field-level restrictions in Cloud Endpoints to dynamically filter data returned to clients.
- D
Use Firestore's document projections to only retrieve the requested fields from the database.
Show answer and explanation
Correct answer: A
Explanation
To restrict return data based on client requests, the most effective approach is to use a query parameter (e.g., fields=...) and implement the filtering logic in your API code. This ensures that only the requested fields are returned, improving both performance and security. While other options like Firestore projections can help optimize database queries, they do not directly address the need to filter data at the API response level.
- A. Correct.
This is the correct answer. Using a query parameter (e.g.,
fields=title,genre) and implementing field filtering in your API code ensures that only the requested fields are included in the response, improving efficiency and security. - B. Incorrect.
Cloud Storage is designed for object storage and does not provide direct support for field-level filtering. This option is not applicable.
- C. Incorrect.
Cloud Endpoints does not natively support field-level filtering. It is primarily used for API management, such as authentication, rate limiting, and monitoring.
- D. Incorrect.
While Firestore supports document projections, this approach only limits the fields retrieved from Firestore, not the data returned in the API's response. Additional filtering logic would still need to be implemented in the API.