Providing the version information through the Accept (request) header along with the content-type (media) in response is the preferred way as this helps to version APIs without any impact on the URI. As we've already learned about content-negotiation, in Chapter 2, Design Strategy, Guidelines, and Best Practices, let's jump to a code implementation of versioning through Accept and Content-Type:
@GetMapping(value = "/investorsbyacceptheader",headers = "Accept=application/investors-v1+json,application/investors-v1.1+json")public List<Investor> fetchAllInvestorsForGiven..()throws VersionNotSupportedException {return getResultsAccordingToVersion("1.1");}
The following screenshot is the output of the preceding ...