A developer is designing a REST API that will be used by multiple client applications. The API must support versioning to ensure backward compatibility. Which approach should the developer use to implement API versioning?
Trap 1: Use different HTTP methods for different versions
Incorrect: HTTP methods are not designed for versioning.
Trap 2: Pass the version as a query parameter, e.g., ?version=1
Incorrect: Query parameters can be cached and may cause issues with proxies.
Trap 3: Use a custom HTTP header to specify the version
Incorrect: Custom headers are less discoverable and may not be supported by all clients.
- A
Embed the version in the URI, e.g., /v1/resource
Correct: URI versioning is straightforward and widely adopted.
- B
Use different HTTP methods for different versions
Why wrong: Incorrect: HTTP methods are not designed for versioning.
- C
Pass the version as a query parameter, e.g., ?version=1
Why wrong: Incorrect: Query parameters can be cached and may cause issues with proxies.
- D
Use a custom HTTP header to specify the version
Why wrong: Incorrect: Custom headers are less discoverable and may not be supported by all clients.