Writing API documentation that developers won't hate
Tags: entrepreneurship
Published: 2021-06-29 10:18:01

API documentation is the #1 factor that impacts the adoption of your APIs. If you want to grow the adoption of your APIs, you want developers to be able to 
<ol>
<li>Get started quickly</li>
<li>Put the API to use with the least chances of failures</li>
</ol>

Before diving into the details of how you should write the documentation, let's investigate from the perspective of a developer who just landed on your API documentation page.

<h2>The ideal journey of a stranger to becoming a champion API user</h2>

Before this stranger becomes a champion API user, they are a learner.

>Good API documentation makes the learning experience rewarding, fun, and engaging.

Here's a framework to make this learning journey great, from beginner to champion level.

<ol>
<li>Get their attention by answering - why should they care about this API?</li>
<li>Get them invested in learning by quickly getting them to the first "Joy of Making" using your APIs. 
A good tactic to do so is to use "Dumb Examples" (Inspiration: Stripe Docs - Get Started -> Clone a sample project)
Note: "Dumb Examples" are the examples that serve everything to build and feel accomplished quickly(hint: copy-paste). They are dumb from the perspective of a champion API user. But from the perspective of a new user, these examples make them feel powerful because of what they can do with your APIs with almost no effort.</li>
<li>Explain the building blocks used in "Dumb Examples" by "Hand-waving"
Note: Explaining too much, too early leads to mental fatigue. Hand-waving is a technique where you either skip explaining some important fundamental concepts or explain them in an oversimplified language. You do so to get the learner get a high-level overview. During this initial phase of learning, prioritize understanding over accuracy.</li>
<li>Introduce them to tutorials that explain concepts in a  structured manner for most popular use cases(Inspiration: Gatsby Tutorials)</li>
<li>Provide a structured reference for advanced usage (Inspiration: Stripe API). Here we are prioritizing accuracy over understanding. This is the final source of truth for the API users. A simple mistake here can lead to bugs.</li>
<li>Provide them a support channel where they can get answers to their questions</li>
<li>Provide them a channel where they can celebrate their small wins while learning about the APIs. This is also a channel for them to get inspired.</li>
</ol>

We move from the least amount of abstraction(i.e. less flexibility to be creative beyond the scope of the example) at Step 1 to the maximum amount of abstraction at Step 5(i.e. maximum freedom to be creative).

<h2>Writing the documentation</h2>

To write the documentation just turn the above workflow upside down.

Start with

<ol>
<li>Dogfooding:
(This will build foundation for step#7 of Learner journey)
The API development team builds some showcase projects using their API components and shares them in the #celebration channel</li>
<li>The support:
(This will build foundation for step#6 of Learner journey)
Team asks each other questions in the support channel to learn more about the API and make their showcase project better</li>
<li>The source of truth:
(This will build foundation of #5 of Learner journey)
Team creates accurate reference documentation of the APIs, everyone writes about the parts they had written and then organize everything
The tutorials</li>
<li>The hand-wave for building blocks:
(Step#3 of Learner journey)
Team explains the concepts used in their showcase examples built in step #7 of learner. Think of a user who might not yet know about your API at all. Simplify.</li>
<li>The instructions:
(Step#2 of Learner journey)
Team simplifies the showcase example and put together minimal notes to make sure a developer that doesn't know the project yet can set it up on their machine easily</li>
<li>The package:
(Step#1 of Learner journey)
Put together the homepage with a tagline that attracts strangers to explore the project with some quick links to try out the examples, and connects everything from Step 1-7</li>
</ol>

<h3>Improving the documentation</h3>

After a great start of writing the documentation, you would want to iterate to make things better

* Review API documentation usage and prioritize the next action items
* Make the navigation better, make it easy to find the right pages within the website
* Review questions people ask in support channels
* Allow documentation users to give you feedback about the documentation(Inspiration: Mongodb docs)
* Work on search engine optimization to get people to the right pages when they search on google(or any other popular search engine)
* Follow good version practices and have an easily discoverable CHANGELOG. (Inspiration: Electron release notes). Help the user choose the right version and make a quick decision whether to upgrade or not. A good inspiration for this - mongodb docs(notice how they share "starting in version 4.4" in the documentation against each feature - it helps people make good decisions).
* Think about communication strategy to handle deprecation notices. Think about how you can let the API users know about the deprecation faster and more frequently. Can you build SDKs - so that you can highlight the deprecation notice right when developers integrate APIs? What alternative communication channels(e.g. email, blog, etc.) should you use to remind users about the deprecation?

### Conclusion
We acknowledge that an individual's willpower to learn is limited. So we destructure their learning journey into tiny building blocks. We build their understanding of the APIs from level 0 to level 1, then to level 10, and then eventually to level 100.

After we understand these user's learning journey milestones, we prioritize the tasks mentioned in the article to start writing good documentation and keep moving towards better documentation, one level up at a time.

Originally published on [Invide](https://blog.invidelabs.com/how-to-write-great-api-documentation/).