API VERSIONING IN LARAVEL (A SHORT STORY)

API VERSIONING IN LARAVEL (A SHORT STORY)

Headless applications are really dominating on today’s internet. Decoupling your back-end and user interface comes with many benefits, from re-use to separation of concerns. Since we have decoupled our front-end and back-end, there has to be a channel of communication between both parties. We have plethora of communications methods to choose from ranging from, SOAP API, REST API etc. In this article we will be focusing on REST API. But we do face a very common issue when it comes to developing and managing our APIs, which is versioning our APIs.

Let us paint a scenario a firm developed a financial application called Pay X. To display the amount a user has in his/her account. An API endpoint "pay-x/api/account-balance" returns JSON data that contain a wallet property which holds our wallet balance. E.g.

 {“wallet:53500}

A mobile app, web app and desktop application were built to consume the API. Everything is working fine and dandy. Two years down the line, our app was purchased by one of the top dogs in tech. Unfortunately, the new company has a different naming convention, instead of using the word wallet they use “STASH”. In a bid of sticking to the convention. The developers were told to revamped the user balance API and returned something like

{“stash:53500}

Here comes the problem, A customer tried to access the app via the web interface, and found out that the app started acting funnily. The customer tried the mobile app, the app was crashing. It is surprising to the user because yesterday this damn app was working fine. What happened? Before you say Jack Robinson, your customer care line is about to blow up, customers showing their displeasure. The IT team has been sent to a state of panic, Junior devs should take the backseat, Senior devs should prove their worth screams the CTO.

It didn’t take long before the find out the issue was because the client side is not in sync with the recent changes. The client side is trying to access the wallet property in the response json, mean while it has been changed to stash. Easy pie says the Front-end dev he/she quickly updated her code and boom everything is working fine. The same issue was corrected on the mobile and desktop application too. The web front-end team is relieved, it is working fine on our end they say in unison.

The overall mood is not still calm. To be continued.