Ever tried to put together a complex piece of furniture without the instructions? We all know that’s typically a recipe for disaster. But that’s exactly what some companies expect developers to do, when they have API documentation that’s hard to find, poorly maintained, or difficult to understand…or worse yet, don’t have any API documentation at all 😱
As Ruben Vermeersch said, “Your APIs are only as good as the documentation that comes with them. Invest time in getting docs right.” If you want developers to successfully use your API and enjoy the experience of using it (and you do, or the API wouldn’t exist in the first place), your documentation needs to get them to first call as fast as possible.
Whether you’re learning the ropes for the first time, looking for a refresher course, or want to improve your existing API documentation, we’ll walk you through what exactly API documentation is, why writing good docs matters, and share our best practices and tips for writing it along the way. Let’s get started 💪
What is API documentation? 📖
For most developers, API docs are a means to an end. Devs want all the details about how to use your API and successfully integrate it into their application of choice. At the same time, they’re often busy people who don’t have the time or attention span to sort through disorganized or unclear information. This means you have to be strategic about how you present your API information.
Think about your API docs like a reference manual:
- A table of contents and clear hierarchy of information indicates where to find important information
- Topics are first outlined at a high level
- Sub-topics have more details and examples to hit your points home
End users should be able to get the gist of things by skimming your docs, but they should also have the option to dive deeper into the details if and when issues come up.
In the past, conversations around APIs have mostly been focused on usability and reliability issues — poor design, uptime, latency, etc. These are, of course, critically important; it doesn’t matter how good your API documentation is if the API itself is badly designed or unreliable. Conversely, though, even the best API imaginable will be painful to use without documentation that’s comprehensive and easy to navigate, ideally with code samples and an interactive playground to give new users a quick way to get started.
Why document APIs? 🤔
Especially if you’re approaching API documentation from a non-technical background, you might wonder why it’s so important. After all, developers are…developers, right? They can pick things up quickly, so surely it doesn’t matter if you don’t have the best docs in the world, as long as they’re acceptable. However, as usual, that’s not the full picture.
Not only are developers a complex and diverse group of individuals, but they are often the decision makers when it comes to API adoption, and/or critical stakeholders in the integration process. Documentation should always be optimized for developer experience. Good developer experience helps to decrease onboarding time, increase user satisfaction, and improve adoption rates.
It’s also worth noting that API-led or API-first companies are becoming more and more mainstream. If your docs are clearer and easier to use than others in your industry, you have a better chance of becoming the first choice for whatever use case your API serves.
Finally, good documentation saves your team money and effort in the long run. Comprehensive references can decrease the amount of support tickets and time spent training new users. One example is ReadMe customer DriveWealth, who found that a manual process for updating documentation created more support tickets, as customers would occasionally see outdated information before the team could finish updating it.
How does API documentation impact developer experience? 🧑💻
Your goal is for your API documentation to establish a great developer experience. On the most basic level, your documentation should be clear and thorough, accurate and up-to-date, and simple enough for someone without any prior API experience to use.
That’s the bare minimum, though. Ideally, a documentation hub will differentiate between how-to guides and API references, contain code snippets with step-by-step tutorials built around those snippets, and include an interactive playground to help developers start using the information right away. If you really want to go the extra mile, you can add community elements so developers can interact with other users (and your team) to get the information they need.
These small things add up when it comes to API adoption. Remember: if your API docs offer a subpar developer experience, your end users might just choose a competitor API instead.
Want to learn more about developer experience? Start here:
- Why DX Matters: Driving API Success with a User-First Approach
- Guide to Developer Experience
- Webinar Recap 🎤 Developer Experience, API Performance, and More with AWS (with our very own CEO!)
- Hubs We Love ❤️ Little Details With a Big DX Impact
How to get started documenting your API ✍️
Writing API documentation can seem daunting — there’s just so much information to distill. That’s why many in the API space rely on tools like OpenAPI as a starting point. OpenAPI offers a powerful ecosystem of tools to get comprehensive API documentation up and running quickly, so users can update their docs as the API evolves.
Whether you opt for OpenAPI or decide to document your API manually, follow these four steps to get going:
- Know your audience. Everyone knows that API docs are primarily for developers. But not all developers have the same level of experience, and it’s becoming increasingly common for people in other roles to also interact with APIs in their day-to-day work. As a best practice, aim to publish documentation that can be used by people of all skill levels.
- Understand the API adoption journey. Put yourself in the shoes of a developer who’s never come across your product before. What are the use cases they’re solving for? What other ways might they use your API in the future? Keep asking yourself this series of questions and map out the user journey, step-by-step. This can help you create an outline and structure for your documentation.
- Edit and edit again. No documentation is perfect at the outset. It goes without saying that you should use spell check and aim to keep sentences and paragraphs short. You can also read your docs out loud — any confusing spots or unnecessarily long sentences will become much more obvious. Do they make sense? Is there any missing context or information?
- Structure for skimmability. Even if the content itself is good, it will probably get skipped over if it’s all one massive block of text without any clear hierarchy of information. Aim to create short paragraphs, bold important information, use numbered and/or bulleted lists when it makes sense, and have clear headers and subheaders to break up the text.
- Peer review. Despite your editing efforts, there are bound to be mistakes you don’t find. Set up a peer review system where teammates read your documentation, test out your coding samples, and work through your tutorials. You’ll be glad you had a second pair of eyes to examine your docs before releasing them to the public.
Fundamental components of API documentation 🌟
There are plenty of ways to provide API guidance to your end-users: topical guides, tutorials, and support forums, to name a few. No matter what you go with, there should always be these essential sections in your docs:
- Authentication: Each API handles authentication differently, so it’s vital to describe how your API does authentication upfront. Pretend you’re a new developer and showcase the authentication process in detail, from initializing API keys to how to send them in your API requests, and anything else they might need to know.
- Error messages: Listing out every possible error message won’t make for very useful docs. Providing background on your errors and how to troubleshoot once one occurs is much more practical. (Learn more about how to write good API errors here!)
- Endpoints: Help your users understand the best use cases for each endpoint and/or set of endpoints. The same use case might have multiple ways to get the job done, so it’s critical to distinguish each of them. The more explicit, the better!
- Changelog: An API is never “finished,” so you need to establish a process for updating documentation as your API evolves. This keeps your docs fresh and shows developers that your API is getting the engineering attention it deserves.
Successful API calls ☎️
In addition to the fundamentals, you’ll want to get specific about what users should expect from a successful API call. To ensure you’re not leaving them in the lurch, be sure to include:
- HTTP status code and message examples: Every error message should be documented alongside its HTTP status code, and the messages themselves should include detailed stack trace information and details on fixing the issue.
- Request parameter examples: Even if your API is extremely intuitive, providing request examples is always a good idea. Beyond explaining what each parameter does, give a real-life example for each one, so it’s crystal-clear what the API expects.
- Code samples and tutorials: Developers usually have an end goal in mind when they begin the API integration process. So why not put some code samples of the most common use cases front and center? Each sample should have detailed context for each step, as if you’re taking them on a live tour of your API. If you have the time, you can insert hints or tips on how to adjust the example to work for other related use cases.
- SDK examples: SDKs are a great way to abstract away the complexity of HTTP APIs. SDKs may include built-in types or other kinds of documentation, but that may only go so far. Be sure to reference relevant SDK examples so that users can build with your SDK successfully.
- Static vs interactive documentation: Think about buying a car — rather than just reading about it online, you want to give it a test drive. Developers also want to try before they “buy." They want to know that your API works for their use case and won’t cause any major issues before proceeding with the integration. To ease their worries, give end-users a playground or sandbox they can use to test out responses to various endpoints without deploying real code.
All together now... ✅
In a nutshell, outstanding API documentation is straightforward and educational. Review these best practices for writing API documentation to ensure your docs are checking off all the boxes. Your docs should be:
- Making your developers’ lives easier
- Digestible no matter the audience’s level of technical expertise
- Well-planned and in a logical order
- In an easily navigable layout
- Written with appropriate, popular use cases in mind
- Filled with examples, tutorials, sample code, and error handling
- Free of spelling and grammatical mistakes that could confuse the reader
- Interactive, with real-life examples
- Maintained with every release, with updates recorded in a changelog
What tools should I be using to document my API? 🛠
When you’re starting, it’s often best to use OpenAPI to document your spec. Instead of writing reference pages by hand, users can import OpenAPI files to reference pages and push changes to docs in a few seconds.
Once you’ve got a baseline API reference, it’s important to decide whether you’re going to use static or interactive documentation. Interactive documentation lets developers make live calls to your API straight from your docs. This form of documentation eliminates the need for a full developer environment in order to make API calls, saving developers time and frustration. While static documentation might be a simpler way to get started, giving live results is a much quicker way to showcase what’s possible with your API.
Ready to get started? 💪
Outstanding API documentation is the cornerstone of a superb developer experience. If your docs aren’t something developers rave about, you’re limiting your API’s potential before you’ve even started. Word of mouth is always the best advertising, so why not get that going for your API?
If you’re looking to get started — whether you’re building from the ground-up or revamping stale documentation — we’d love to help. Our team is always happy to answer questions about API documentation and how you can improve yours. You can reach out here to get a demo and learn more, or head here to sign up for a free trial.