Google Professional Cloud Developer Question 323
Single answerGoogle Cloud PlatformYou are developing a REST API for an e-commerce platform hosted on Google Cloud. The API is already used by multiple clients, and you need to introduce a new feature that requires adding a field to the existing API response. How can you ensure backward compatibility while implementing this change?
- A
Add the new field to the response but keep it optional.
- B
Remove unused fields from the response to make room for the new field.
- C
Add the new field to the response and make it mandatory for all clients.
- D
Create a new API version for the new feature and deprecate the current API version.
Show answer and explanation
Correct answer: A
Explanation
To ensure backward compatibility in REST APIs, changes should not disrupt existing clients. Adding a new optional field to the response allows the new feature to be implemented without breaking functionality for clients that do not expect or use the new field. This approach maintains the integrity of the current API while enabling new capabilities.
- A. Correct.
This is correct because adding a new field as optional ensures existing clients can continue to function without requiring immediate changes, maintaining backward compatibility.
- B. Incorrect.
This is incorrect because removing fields can break existing clients that rely on those fields, violating backward compatibility principles.
- C. Incorrect.
This is incorrect because making the new field mandatory would force all existing clients to adapt, breaking backward compatibility.
- D. Incorrect.
This is incorrect because creating a new API version is not necessary for this scenario. Backward compatibility can be achieved without introducing a new version by adding fields as optional.