Code versioning best practices
Over time, your application will evolve and, at some point, you will be at the point where you are wondering what you will do with the API of any of your microservices. You can keep the changes to a minimum and be transparent to the users of your API, or you can create different versions of your code. The best solution is versioning your code (API).
The well-known and commonly used ways for code versioning are as listed:
URL: In this method, you add the version of your API inside the URL of the requests. For example, the
https://phpmicroservices.com/api/v2/user
URL indicates that we are using thev2
of our API. We used this method in our examples throughout the book.Custom request header: In this method, we do not specify the version in our URL. Instead, we use HTTP headers to specify the version we want to use. For instance, we can do a HTTP call to
https://phpmicroservices.com/api/user
, but with an extra header,"api-version: 2"
. In this case, our server...