Api First Development

Change is the only constant.

In today’s world, the word “computation” is being used in systems other than computers more frequently. “Internet of things” is coming along nicely. This imposes some changes in traditional concept of software.

In the evolution of web application, MVC pattern was definitely a milestone. It allowed software engineers to successfully de-couple business logic from UI dependencies and it has been the defacto of writing good, robust web applications. However, with the pace of changes happening today we, as software engineers, need to re-think this model.

What’s MVC anyway ?

MVC stands for model-view-controller, as the names suggest, model represents business objects in you application. View is the HTML used to interact with your application and Controller is the glue that holds these two together. If we take a bird’s eye look at this architectural pattern. We can easily think of view-layer as a client interface, which wraps up business logic and computation provided by your application.

It’s not just one view now!

Today, with increasing popularity of smart-phones and BYOD, end users prefer doing their computation from mobile devices - tables, smart-phones etc. Now, to enable users use your application via multiple platforms. It is not sufficient to design application in traditional MVC pattern. Ofcourse you can use responsive web design to share one view between many clients, but it doesn’t have that native look and feel, more importantly speed that native apps bring in picture.

HTML5 is the thing of ‘future’!

HTML5 might seem promising, but it’s just not there yet. Due to poor support for JavaScript heavy applications, using HTML5/client side MVC will make your application insanely slow on some devices. Second option is to make native mobile apps and call APIs from it. So ultimately we’ll end up re-implementing some of the logic.

Enter API first

In order to solve this problem, first we need to take the view-layer out from the picture and just focus on the business logic of application. Next think about what operations user can perform with your application, could be data manipulations, or some other form of computation. Wrap this operation in a URL and you have an API! So what changed in this approach ? We focused on the logic first and not the view, doing so we de-coupled our web application one step further. Now any view can be plugged in or out very easily.

Best practices to follow

Understanding REST principles is of utmost importance when designing APIs. There are some common considerations while following API first development. Here’s a list of few

  1. Keep API structure meaningful
  2. Keep APIs stateless
  3. Use HTTP verbs to fullest
  4. Document your APIs - its really important!

Conclusion

API first development allows you to highly reuse the code, helps you implement SOA, and boost overall time required for development.

Further reading


Chinmay Kulkarni

Full stack polyglot developer and amature guitarist. I like to code in python, golang and JavaScript. Currently, I am pursuing MS from Carnegie Mellon University. I am a machine learning enthusiast and an avid open source contributor. You can reach me here -
GithubLinkedInTwitter


Share this article