Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Secrets to Great API Design

DZone 's Guide to

Secrets to Great API Design

Let's find out the secrets to great API design.

· Integration Zone ·
Free Resource

Image title

What are the secrets of really good API design?

The way we build software is changing.

Now, companies are going to market faster and building features at unprecedented rates all thanks to the surge in API platforms.

The API economy has exploded in recent years with thousands of new APIs coming to market and reinventing the way developers build software. There's an API solution for virtually every need: payment APIs, communications APIs, shipping APIs, and thousands more. So how do you build an API that stands out from the competition?

Whether your goal is to build an open-source API, an API platform, or an API to help other developers integrate with your products, there's one thing that makes successful APIs stand out from the rest: You must build an API that's optimized for developer experience (DX).

Whether you're a product manager, technical co-founder, or a developer yourself, you need to keep your end-users at the forefront of every API design decision. By adopting this mindset, you are equipping your own users to use your service to innovate. Facebook is a prime example of this. In the early days of Facebook, developers were building games on their platform, but Facebook was profiting from their effort — all because they grew a robust community of developers from within their social media gaming platform.

Putting your API users in the driver's seat by empowering them to build customized app experiences (or even experiences you didn't know your platform could deliver) distinguishes you among the sea of ever-growing and changing SaaS solutions.

In this article, we'll discuss the following facets of API design:

  1. Shorten time to value
  2. Treat your docs like the homepage of your website
  3. Make your abstractions consistent within your API
  4. Future-proof your API
  5. Change is inevitable, manage it well

But before we dive in, it's worth mentioning these table-stakes functionalities of every API. Since these are fairly straightforward, we won't dive into them in this article:

  • Your API should always be on (99.9% uptime or higher)
  • Your API should be lightning fast (keep response times low)
  • Your API should seamlessly update (no breaking changes)
  • APIs should expose building blocks, not static solutions

Got those down? Great, let's dive in!

You may also like:  Understanding API Design

1. Shorten Time to Value

A great API will shorten the time to value (TtV) (i.e., the amount of time it takes them to see value from the API) for developers. Shortening TtV takes place even before a developer starts integrating with your API. You can prove your API's worth in the docs themselves by allowing users to test a cURL response in the docs — you can see an example of this in the Nylas docs.

Even when you're providing test tokens, it's critical to use the first-time-every-time framework. With the test token example, most developers expect the test token process to work exactly as prescribed, while others aren't as familiar with how cURL commands operate. This is where excellent documentation comes into play.

Match Users' Expectations

When building an API, keep one question top of mind: Does it do exactly what your users expect it to do on the first try?

In most cases, this involves taking a "do the right thing right the first time" approach to your API's usability. You can shorten your time to value (TtV) by delivering an API that solves a challenging technical problem quickly and efficiently from the first interaction onward. Check in periodically to test your API and ensure that the first interaction is smooth and has a big "wow" factor.

Increase Efficiency With SDKs

SDKs are one of the best ways to reduce friction in the integration process. It's critical to ensure developers can figure out the parameters of your API's SDK integration as quickly as possible. Efficiency is both meant to save coding time, and eliminate any mental roadblocks while learning how your API functions within their framework of choice. With a simple Ruby, NodeJS, or Python SDK, developers can build a full-featured integration in a fraction of the time.

While SDKs take time to create and maintain, they dramatically improve the developer experience and reduce TtV.

2. Treat Your Docs Like the Home Page of Your Website

Think of your API docs as the front page of your website. It's the central place users will bookmark and start using; it should be user-friendly, intuitive, and follow a logical flow.

Your API docs need to be inherently discoverable and easy to use - just like the API itself. Stripe is an excellent example. Its docs are easy to navigate, with a clear table of contents on the left-hand sidebar, and a simple 6-step process for successfully charging a payment via the Stripe API:

While it's important for you to do the valuable groundwork of ensuring API usability and the TtV is quick, your interface is only as usable as your documentation. And your documentation is only helpful when it's easily discoverable.

Your documentation library should be organized in a consistent way with built-in search functionality - especially if there are a lot of complex elements to your API that require thorough documentation. This means that your docs must be logically organized, scannable, and provide contextual coverage across your entire API integration process.

Not only should your documentation be discoverable, but it should also be contextual. In other words, they should show up in each developer's programming language of choice. Listing all the technical guidelines for how to use your API is not enough, you need to provide signposts that can help provide context for specific developer scenarios. In other words, you will need to use a wide range of affordances when creating your documentation. This may even mean adapting your technology to meet the technology needs (SDKs, custom code languages) of each user.

Odds are, developers are using your technology to solve a unique problem, so they will need to look to a wide range of guides, examples, and quick-starts to show them proof that they can use your API in a very specific, scalable way.

3. Make Abstractions Consistent

A developer-friendly API needs consistency. To optimize for usability, you should create workflows that consistently abstract ideas within your API.

You can also get full CRUD on Google and Exchange events with the same POST request. There are no exceptions in the code that would require developers to work in a different way, despite the data model being vastly different for Google and Exchange events.

On the flip side of this equation, it's easy to have a too-fine focus on consistency so that you can miss opportunities to innovate. For instance, it's possible to delay rolling out exceptions to your API that could evolve your product in the name of abstraction consistency, so be sure to find a reasonable balance.

4. Future-Proof Your API

Today, the world tends to move data in and out through JSON. Depending on your audience, that might be different, and in a couple of years that might look different. It may be better to add GraphQL APIs.

Developers will look to your API to remove friction from their workflows. If your API doesn't follow the latest frictionless trends in the development world, you'll lose a lot of interest. While trends in software engineering are constantly evolving, you want to at least be aware of the developing trends and consider which ones to incorporate into your API. For example, most developers expect a JSON response from a cURL command. JSON may seem like the obvious response, but this wasn't always the case.

By sending simple JSON responses in lieu of binary XML and SOAP, we're able to minimize friction and create a better developer experience.

5. Change Is Inevitable — How Well You Manage It Is Not

When building an API, change is inevitable. SOAP APIs lead the way to REST APIs, and REST APIs are the precursor to GRAPH APIs. JSON is the industry-standard file format for modern APIs, but this will likely change as technology develops. Since change is inevitable, the only thing you can do is embrace it and try to prepare for change by:

Built-in Versioning From Day 1

Innovative digital payment provider Stripe takes a fairly strict approach to change where it creates new versions of the API each time a change is necessary (effectively changing nothing about old versions of the API). This requires it to support every version of the Stripe API from its initial conception to the latest rollout. Making significant changes to an API can have a severe business impact if done hastily or incorrectly, which is why some companies choose the same method of versioning as Stripe.

Communicate Changes Early and Often

On the other side of this spectrum, Facebook makes changes to its API quickly and frequently — much to the delight and/or chagrin of web and mobile app developers around the world. It's very good at communicating these changes in advance (or at least better than average) so developers can prepare, so few to no changes disrupt in their end-users' services. If you don't have the resources to build versioned systems like Stripe, being able to communicate well about the changes is a lower-budget, smaller-scale way to deal with that.

API versioning can come in varying levels of complexity. Simple version numbering systems (V1, 1.1, 1.2, and onward) scale well and fairly effectively.

Summary

Successful developer experiences are built on trust and reliability. You can build trust with developers by ensuring your API works as expected from the first try onward. It sounds simple, but anyone who has done it knows it's quite challenging. The good news is that by following the best practices above, you're on track to build a great experience, an exemplary API, and an excellent developer relations foundation.

Further Reading

Implementing an API-First Design Methodology

RESTful API Design Principle: Deciding Levels of Granularity

Topics:
integration ,api design ,secrets to great api design ,api platform ,apis ,api users

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}