This chapter will teach you to stand out among the rest of the developers. This is possible by developing and executing the strategies learned in this book with style, and by following concrete standards.
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:
https://phpmicroservices.com/api/v2/user
URL indicates that we are using the v2
of our API. We used this method in our examples throughout the book.https://phpmicroservices.com/api/user
, but with an extra header, "api-version: 2"
. In this case, our server will check the HTTP header and use the v2
of our API.Accept
header. For our example, we will make a call to https://phpmicroservices.com/api/user
but our Accept header will be "Accept: application/vnd.phpmicroservices.v2+json"
. In this case, we are indicating that we want version 2 and the data will be on JSON.As you can imagine, the easiest way to implement versioning in your code is with the version code inside your URL but, unfortunately, that is not considered the best option. What most developers consider the best way of versioning your code is to use HTTP headers to specify the version you want to use. Our recommendation is to use the method that suits your project best. Analyze who will use your APIs and how, and you will discover the versioning method you need to use.