Nobody Wants To Use Your API
Tags: product, api, design
Published: 2019-11-22 13:52:09

---
title: Nobody Wants To Use Your API
published: true
date: 2019-11-22 00:00:00 UTC
tags: product, api, design
canonical_url: https://yiming.dev/clipping/2019/11/22/nobody-wants-to-use-your-api
---

<section id="content" role="main">
    <div id="outline-container-sec-" style="padding-top: 70px">
        <div></div>
            <p>
When writing an API endpoint or a function, I often find myself being obsessed with it, adding tons of toggles or options so this endpoint handles too many use-cases.
In the end, not all of the toggles are used by the client.
Even worse, the code is too complex to maintain.
</p>

<p>
So how do we, as programmers, avoid this pitfall?
I think we should apply some product thinking here.
First, think of our API as our product.
Then, realize that <a href="https://www.smashingmagazine.com/2016/01/nobody-wants-use-your-product/">Nobody Wants To Use Your Product</a>.
Finally, we write simple APIs that are easy to learn and easy to use.
</p>

<div id="outline-container-orgc0acb7b">
<h2 id="orgc0acb7b">API is the only product of programming</h2>
<div id="text-orgc0acb7b">
<p>
What is an API, anyway?
According to <a href="https://en.wikipedia.org/wiki/Application_programming_interface">Wikipedia</a>,
an API is <i>a "contract" between "the client" and "the server"</i>.
</p>

<p>
Notice that "the client" and "the server" don't need to be talking over a network.
So we are defining an API ("a contract") at every level of our application:
</p>
<dl>
<dt>When writing a function, we are designing an API for the callers of this function.</dt>
<dd>What's the name of the function?
What arguments does this function need?
What results would this function return?</dd>
<dt>When writing a library, we are designing an API for other programmers.</dt>
<dd>What classes/modules does this library have?
How to use these classes/modules?
What results can these classes/modules achieve?</dd>
<dt>When writing a RESTful controller action, we are designing an API for the browser.</dt>
<dd>What's the path to this action?
What's the verb to use here? (GET, POST, PUT, DELETE)
What's the response structure?</dd>
<dt>When writing a page view with HTML, JS, and CSS, we are designing an API for the user.</dt>
<dd>What's this form used for?
What would happen after clicking this button?
What's the content of this page?</dd>
</dl>

<p>
And everything else we do, is to fulfill the API ("the contract") we defined.
</p>
<dl>
<dt>Write business code</dt>
<dd>Fulfill the business logic contract.</dd>
<dt>Write automated tests</dt>
<dd>Make sure we fulfill the business contract as specified.</dd>
<dt>Fix various bugs</dt>
<dd>The contract was broken, we need to fulfill it again.</dd>
<dt>Improve performance</dt>
<dd>Fulfill the performance contract (return the results within <code>x</code> seconds).</dd>
<dt>Document the API</dt>
<dd>Explain the contract to the user.</dd>
</dl>

<p>
Or we can think it from the opposite.
If you as "the server" don't expose an API to "the client", then it doesn't matter how much work you do behind the scenes.
Because nobody can use it anyhow.
</p>

<p>
So API is the most important, if not the only, product of programming.
</p>
</div>
</div>
<div id="outline-container-orgf5ccf85">
<h2 id="orgf5ccf85">Nobody wants to use your API</h2>
<div id="text-orgf5ccf85">
<p>
After understanding that <code>API == product</code> in programming, we can start to think from a product perspective.
In the article <a href="https://www.smashingmagazine.com/2016/01/nobody-wants-use-your-product/">Nobody Wants To Use Your Product</a>, Goran Peuc summarizes this presumption about human nature as:
</p>
<blockquote>
<p>
People are not really into using products.
Rather, people are more interested in the end result and in obtaining that result in the quickest, least intrusive and most efficient manner possible.
</p>
</blockquote>

<p>
The same product thinking applies to programming as well.
Other programmers are not really into using our API.
They may use our API to get some data.
Or they may use our API to avoid reinventing the wheel and thus simplify their own code.
In a word, they use our API to <b>achieve a result</b>.
</p>
</div>
</div>
<div id="outline-container-org1e0f56d">
<h2 id="org1e0f56d">KISS (Keep it simple, stupid)<sup><a id="fnr.1" href="#fn.1">1</a></sup>
</h2>
<div id="text-org1e0f56d">
<p>
So what can we do as API designers?
If nobody wants to use our API, and people use it only because they want to achieve a result, then we should make our API really simple.
And by "simple", I mean easy to learn and easy to use.
It's simple to say, but it's hard to do.
The ultimate goal requires us to spend tons of efforts:
people can spend almost no time to learn our API and start using it.
So they can focus on their own concerns, and spend more time figuring out how to succeed in their own way.
</p>
</div>
</div>
<div id="footnotes">
<h2>Footnotes: </h2>
<div id="text-footnotes">

<div>
<sup><a id="fn.1" href="#fnr.1">1</a></sup> <div><p>
<a href="http://principles-wiki.net/principles:keep_it_simple_stupid">Keep It Simple Stupid (KISS) {Principles Wiki}</a>
</p></div>
</div>

</div>
</div>
    </div>
</section>