An API-First Development Approach

Regardless of the type of application you’re developing, chances are if you’re developing it for the cloud, then your ultimate goal is to have that application be a participant in an ecosystem of services. In that case I would take a look at the concept of API first.

Why REST API?

The API Economy is growing rapidly and companies are joining the fray in making APIs as an integral part of their growth strategies.

APIs Are Everywhere

Tech giants like Apple and Google are gearing towards API centric future. The surfacing of new interconnected hardware, wearables and soon driverless cars, just show how important APIs is in our lives.

What is API-First?

A lot of companies starting with building web or mobile applications, only then as a side project they build an API for third party companies or for integration purposes. They see it then as two channels: one web \ mobile channel and one API channel. Problem with this approach is that it results in an "artificial API" that wasn't properly built and tested during design.

A better approach is to build the API first and build your web or mobile applications on top of that API. This forces you to design an API and use it for your own app so this will be a more "real world" and developer friendly REST API.

API First Development is a strategy where the first order of business is to develop an Application Program Interface putting your target developer’s interest then build the product on top of it be it a website, mobile application or a SaaS software. By building on top of APIs with developers in mind, you and your developers are saving a lot of work while laying down the foundations for others to build on top of.

To simplify think about it like this:

You are building cloud-native applications, and after code gets checked in to your repository, tests are automatically run, and you have release candidates running in a lab environment within minutes. The world is a beautiful place, and your test environment is populated by rainbows and unicorns.

Now another team in your organization starts building services with which your code interacts. Then, another team sees how much fun you’re all having, and they get on board and bring their services. Soon you have multiple teams all building services with horizontal dependencies[1] that are all on a different release cadence.

What can happen if no discipline is applied to this is a nightmare of integration failures.

To avoid these integration failures, and to formally recognize your API as a first-class artifact of the development process, API first gives teams the ability to work against each other’s public contracts without interfering with internal development processes.

Even if you’re not planning on building a service as part of a larger ecosystem, the discipline of starting all of your development at the API level still pays enough dividends to make it worth your time.

Why API-First Development?

Development process is currently not parallel, but synchronous.
Once a new service or a new feature is in a need for development, the R&D teams are starting to work on the design. Once done, the backend team is starting to write a prototype (other teams like frontend and Q&A are waiting). Once the prototype is done an API document can be prepared and shared for the different teams (Q&A, frontend).

When change is needed because of a feature, bug, improvement or enhancement, this cycle will begin again, wasting valuable development time and decreasing time-to-market for the new service.

Code First Approach As you can see in the picture above, first the back-end team is starting to develop and implement a new API. Second, the API is being give to the front-end teams and testers for using and testing it. Third, the front-end teams and testers are building SDKs, Tests and more to interact with the API. This is synchronous development.

API-First development will allow parallel development by all teams without the need to wait for changes to be released by one team or another.

API First Approach Here in the picture above, we can see the first the APIs that are created are mocks. Second, both back-end, front-end and test teams are starting to work with the mocked APIs. Once the API is ready all teams can switch to the production or staging API. This saves a lot of development time.

RestCase provides mocking, debugging, automatic documentation and testing tools for APIs, with team notifications and sharing across all the design & development stages and enables to work in collaborative API-first approach.

RestCase
REST API Development Platform

Building services API first

These days, the concept of mobile first is gaining a lot of traction. It refers to the notion that from the very beginning of your project, everything you do revolves around the idea that what you are building is a product to be consumed by mobile devices. Similarly, API first means that what you are building is an API to be consumed by client applications and services.

Cloud native is more than just a list of rules or guidelines. It is a philosophy and, for some of us, a way of life. As such, there are guidelines for cloud native that might not necessarily map to specific physical requirements imposed by the cloud but that are vitally important to the habits of people and organizations building modern applications that will be ready for future changes to the cloud landscape.

Built into every decision you make and every line of code you write is the notion that every functional requirement of your application will be met through the consumption of an API. Even a user interface, be it web or mobile, is really nothing more than a consumer of an API.

By designing your API first, you are able to facilitate discussion with your stakeholders (your internal team, customers, or possibly other teams within your organization who want to consume your API) well before you might have coded yourself past the point of no return. This collaboration then allows you to build user stories, mock your API, and generate documentation that can be used to further socialize the intent and functionality of the service you’re building.

All of this can be done to vet (and test!) your direction and plans without investing too much in the plumbing that supports a given API.

These days, you’ll find that there are myriad tools and standards to support API-first development. There is a standard format for API specification that uses a markdown-like syntax called API Blueprint or Swagger. These formats can be used by code to generate documentation and even REST API server mocks, which are invaluable in testing service ecosystems.

In other words, there is absolutely no excuse for claiming that API first is a difficult or unsupported path. This is a pattern that can be applied to non-cloud software development, but it is particularly well suited to cloud development in its ability to allow rapid prototyping, support a services ecosystem, and facilitate the automated deployment testing and continuous delivery pipelines that are some of the hallmarks of modern cloud-native application development.

This pattern is an extension of the contract-first development pattern, where developers concentrate on building the edges or seams of their application first. With the integration points tested continuously via CI servers, teams can work on their own services and still maintain reasonable assurances that everything will work together properly.

API first frees organizations from the waterfall, deliberately-engineered system that follows a pre-planned orchestration pattern, and allows products to evolve into organic, self-organizing ecosystems that can grow to handle new and unforeseen demands.

Summary

If you’ve built a monolith, or even an ecosystem of monoliths, that all interact in tightly coupled ways, then your ability to adapt to new needs or create new consumers of existing functionality is hindered. On the other hand, if you adopt the mentality that all applications are just backing services, and that they should be designed API first, then your system is free to grow, adapt to new load and demand, and accommodate new consumers of existing services without having to stop the world to re-architect yet another closed system.

Live, eat, and breathe the API-first lifestyle, and your investment will pay off exponentially.

Guy Levin

Read more posts by this author.

comments powered by Disqus

Subscribe to REST API and Beyond

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!