Google Professional Cloud Developer Question 327
Select 3Google Cloud PlatformYou are developing a REST API for an e-commerce platform and plan to introduce a new version of the API to support additional features without disrupting existing clients. You are using Apigee to manage your APIs. Which of the following strategies should you implement to version your API effectively?
- A
Use the URI to specify the version, such as /v2/products.
- B
Deprecate the old version immediately upon releasing the new version.
- C
Use custom request headers to specify the API version.
- D
Communicate version changes to API consumers with proper documentation and advanced notice.
- E
Embed the version number in the query parameters, such as /products?version=2.
Show answer and explanation
Correct answers: A, C, D
Explanation
Versioning APIs effectively ensures that new features can be introduced without breaking existing functionality for current consumers. URI-based versioning is clear and commonly used, while header-based versioning offers flexibility. Proper communication and documentation are crucial for a smooth transition. Query parameter versioning, while possible, is generally discouraged due to potential confusion and poor compatibility with RESTful principles.
- A. Correct.
Using the URI to specify the version (e.g., /v2/products) is a widely accepted practice for API versioning and makes it easy for API consumers to identify and use different versions.
- B. Incorrect.
Immediately deprecating the old version is not a best practice as it may disrupt existing clients. A phased deprecation approach with clear communication is preferred.
- C. Correct.
Using custom request headers to specify the API version can be a flexible approach, especially when you want to avoid changing the URI structure.
- D. Correct.
Communicating version changes to API consumers with proper documentation and advance notice is essential for ensuring a smooth transition for clients.
- E. Incorrect.
Embedding the version number in query parameters is generally not recommended as it can lead to confusion and is less intuitive compared to URI or header-based versioning.