Opinion Time: Should Developers ALWAYS Build an API?

Sponsored by #native_company#
#native_desc# #native_cta#

There's been some talk in my office lately about the practicality of always building API (Application Programming Interfaces) backends for our apps. Some of my teammates argue that it ensures portability, that we can move to newer technologies more readily. Others agree, but say the primary reason is to provide a layer of abstraction between the code and the data (since enough abstractions can solve many problems). I personally have a much more basic problem. I'm at a crossroads, and I need your help, dear reader, to put an end to an endless argument I've been having with myself.

A "No U-Turn" sign on a cloudy day

Our latest major project has an API backend (specifically an HTTP REST service) that handles the data and business logic. This was implemented primarily because we have 25+ data sources (including SQL Server databases, Oracle databases, WCF services, and other APIs) that we need to consume and display to our users through a single, unified web app. My team and I figured that providing a layer of abstraction between the web app and the data sources would greatly help separation of concerns and, in general, make this project easier to maintain in the future. It will do both of those things, I'm sure. I designed it to do those things.

And yet... I hate it.

I hate this API because it will only ever be consumed by one application. It seems like cruft, like code that doesn't serve a purpose other than to artificially divide two pieces of a project (web layer and data layer) that probably don't need to be divided since they won't be reused outside this project. On some level, I want to believe that this API is not needed and should be gone. I want it gone.

Longtime readers will recall that I'm an extreme deletionist. I would much prefer if all code everywhere was deleted, because at least then it couldn't break. I want to think that building this API is a waste of time and code. I want to, I've tried to convince myself that I'm right and I can delete it, and I can't. I find myself forced to reconsider my deletionist tendencies, because I can't quite shake the conviction that always building an API is a good idea.

I don't enjoy having this thought. It goes against my very nature. And yet it draws me in, its siren song slowly turning me mad, persuading me that always building an API, even if it will only ever have on consumer, is correct, is needed, is right.

There are many arguments that can be made in favor of always building an API:

  • Doing so enables movement to other apps. Even if, at the moment, only one app will consume the API, merely having said API will enable other apps to use it in the future.
  • It provides an extra layer of abstraction, which can be changed independently of other layers (promoting separation of concerns).
  • It promotes the Microservices architecture, in which many small APIs or services can be used to build a large, complex app (more specifically, many large complex apps with lots of reuse in the service layer).

To be fair, there's also arguments to be made against always building an API:

  • YAGNI. In many situation, you simply don't need an API, especially for simple apps.
  • The more layers you have in an app, the more difficult it becomes to debug it (though this can be mitigated).
  • It's tacky and I hate it (see the first bullet).

The deletionist part of my brain tells me it's just not necessary! while the rational developer part says who cares, it helps separation of concerns! I can't quite reconcile the two.

So I need your help, dear readers. Please tell me why we programmers should or should not always build an API in the comments below. Not just "yes" or "no" but why and for what reasons. Convince me that my deletionist tendencies are spot on and we don't need to always build an API. Alternately, convince me that my rational developer brain has the right of it and we do want APIs all the time. I want to see arguments for both sides.

I'll gather all the comments into a future post where I see if all of us (me and my readers) can come to a definitive conclusion as to whether or not it is a good idea to always build an API. So let me know what you think!

Happy Coding Opinionating!

Matthew Jones

Matthew Jones

I'm a parent, a husband, a geek, a web developer, and a speaker, in roughly that order.

Read More
Opinion Time: Should Developers ALWAYS Build an API?
Share this