Nov 16 2012

Building your API Early

In an increasingly multi-platform web—full of iPhone and Android apps, social media plug-ins and other third-party developers—building your API first provides unified access to an app’s data. In standard processes you might, for example, build a web front-end in Rails, then later need a phone app that can access and update the same data. An API built as an afterthought can lead to an ad hoc “gluing” of functionalities together, rather than providing the cohesion across platforms that a well-planned one provides.

Defining functionality early

From the developer’s point of view, API-first design encourages defining functionality early and allowing form to follow from it. The presence of API output as raw data means that devs can focus on business logic over interface considerations. This also forces a concentration on the core of an app and the value it will provide, and might help put extra bells and whistles into perspective (“Do we really need that?”).

Fast iteration and efficiency

This method also allows fast iteration on new features. Suppose a Widget model has been changed, and now has many Parts instead of one. If the model is critical to the app, a change like this might cause other sweeping changes across an app’s interface. In many situations, the solution is for a developer to quickly mock up a quick-and-dirty interface that’s just good enough for testing. Once the appropriate features have been accepted, a designer might start nearly from scratch to re-implement forms and other elements in a more aesthetically pleasing way. This is inefficient, and can create a dependency because the designer waits for the back-end portion to be finished before starting their work. API responses can be mocked (once a spec is agreed on), meaning development and design teams can work at the same time, with neither stepping on the other’s toes.

Central documentation

Finally, an API built this way helps to centrally document an application. An API contains all of the central business logic that a developer starting out needs to know, reducing the bus number of the project. It also doesn’t contain cruft that’s (mostly) irrelevant to back-end design, e.g., does making a purchase on the site take multiple page-steps? This kind of information should be packaged in the web app, away from the data manipulation of an API. Some caveats:

  • Story acceptance with APIs might be difficult for non-technical project managers. Indeed, the ideal of being able to separate back-end and UI features given above might be impossible on some projects.
  • Using an API separately can introduce overhead, e.g. separate API servers will most likely need to be maintained from the start.

3 Comments

  1. Mick

    Nice post, we are currently building our API for our new start-up RentEzy.com and I can totally see the benefit of starting out first with the API. I’ve read online that Twitter uses their API for their own site now instead of calling their own internal methods… Cheers

  2. bennett

    Do you have any preferred tools or methods for managing API requirements b/t teams? We’ve got a team of mobile engineers and team of ‘platform’ engineers (the webapp & API) here and I’m still grappling with the best way of defining and maintaining the API requirements b/t them. We have some API specs written in cucumber, but that isn’t as readable as I’d like. I’ve been looking into swagger (http://swagger.wordnik.com) as well.

  3. My experience has been with documenting via specs and the old-fashioned way in READMEs and doc files—by providing sample requests and caveats/restrictions on specific calls. For large projects, the tack I’ve seen chosen is a docs wiki on Github that lays out the hierarchy in detail.

    I haven’t heard of swagger before now, though, and it looks like a great tool for the job. Thanks for the link!

Leave a Comment

Join the discussion. Do not worry, your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>