How to Write API Documentation: The Ultimate Guide

Claudiu
Claudiu
bits and pieces of documentation & marketing 👨‍💻

This guide is for technical writers who want to start writing API documentation or anybody who wears an API writer's hat.

APIs (Application Programming Interfaces) have become the backbone of modern software development, allowing developers to create applications that communicate with each other seamlessly.

The API economy has been booming with a high growth rate in recent years, but creating an API is only half the battle. Without clear and comprehensive API documentation, even the most powerful APIs can be difficult to use, leading to frustrated users and missed opportunities.

That's why writing effective API documentation is so important. By providing clear and user-friendly guides that explain how to use the API, technical writers and developers can help users get the most out of their applications, improve user engagement, and streamline the development process.

In this ultimate guide to writing API documentation, we'll explore the best practices and essential tips for creating documentation that's clear, comprehensive, and easy to use. Whether you're a seasoned technical writer or just starting out, this guide will help you master the art of API documentation and create guides that users will love. So let's get started!

What is an API?

In simple terms, API is an acronym for Application Programming Interface. It is a set of rules, protocols, and tools that allows different software applications to communicate with each other. APIs define how different software components should interact with each other, making it possible for developers to build complex applications that combine the functionality of multiple components.

The essence of APIs is requests and responses. When you take action on your phone, like checking the weather, a request is sent to an API to access and deliver that information.

What is an API? How does it work?

Source: medium.com

What is the difference between REST API and API?

The main difference between REST API and API is that REST API is a specific type of API that follows a set of conventions and principles, while API refers to a general concept of how different software components can interact with each other.

A REST API is a type of web API that is designed to be simple, lightweight, and scalable. It uses a set of conventions and principles to define how applications can communicate with each other over the internet. The term "API" can refer to any type of interface that allows software components to interact with each other. This can include different types of APIs, such as SOAP APIs, GraphQL APIs, or even custom APIs that are designed for a specific use case.

What are the different types of API?

Having a good understanding of the different types of API can be incredibly useful in structuring your content. There are different types of APIs, but 82% of organizations use the OpenAPI Specification (formerly known as Swagger) in their API development. Each type has its own unique characteristics and use cases, but typically the main types of API include:

  1. SOAP (Simple Object Access Protocol) is a messaging protocol that is used to build web services. SOAP APIs provide a standardized way for applications to exchange information over the internet.
  2. REST (Representational State Transfer) APIs are a popular type of web API that are designed to be simple and lightweight. REST APIs use a set of conventions and principles to define how applications can communicate with each other over the internet.
  3. GraphQL APIs: GraphQL is a query language that is used to retrieve data from APIs. GraphQL APIs allow developers to request only the data they need, reducing the amount of data that needs to be transferred over the internet.
  4. Real-time APIs are designed to provide real-time data to applications. These APIs are commonly used in applications that require up-to-date information, such as stock market data, weather data, or social media feeds.

How to write API documentation

API documentation provides a clear and comprehensive guide to using an API, including its endpoints, parameters, response types, and any other relevant information that developers need to know.

Without clear and comprehensive documentation, using an API can be a frustrating and time-consuming experience, even for experienced developers. Good API documentation can make it easier for developers to understand the purpose and functionality of the API, and provide the information they need to use it effectively.

The audience for API documentation can vary depending on the nature of the API and the applications that use it. In some cases, the audience can include both developer and non-developer stakeholders, such as business analysts or product managers who use the products or services.

Even the API-focused technical writers are never actually writing the API endpoints— they are just documenting them with code samples, descriptions, etc., so developers can call them.

Who writes API documentation?

You don't need to be a programmer to write API documentation. Still, API documentation is typically written by technical writers, who work closely with developers to create and explain how to use the API.

Depending on the organization, other stakeholders may also be involved in creating API documentation, such as product managers or project managers. These stakeholders may be responsible for ensuring that the documentation meets the needs of the end-users, and may provide input on the content and structure of the documentation.

  1. Technical writers. This is the group that will most likely handle the API documentation. Usually, writers don’t have programming experience (except if they transitioned from a developer role to a technical one), so they work closely with the devs. As a technical writer, you can learn along the way, and the key is to understand the concepts, not necessarily have the skills to write code from scratch.
  2. API Developers. Who else better knows the code than the people who wrote it? So developers are an obvious choice. There’s a debate around whether they are suitable for writing docs, and, indeed, this is rarely a good idea because developers are famous for being bad writers.
  3. Also, documentation is not a priority for a developer, but it doesn’t mean that they shouldn’t write at all. Developers need to document enough of their code so that writers get the idea and add information that is not obvious. Having notes is not complex, and it can come in the form of code documentation or notes.
  4. Whoever wears the hat. Sometimes you will find product owners, startup founders, content writers, and everything in between. The essential skill here is to be good at writing and have technical knowledge. No matter who wears the API writer’s hat, the role must bring clarity, structure, and explanation to the documentation.

What does a technical writer need to know to write API documentation?

Writing API documentation can be a complex process, but it's important to understand how APIs work and how to use the correct terminology to talk about them. As a technical writer, you need to be able to write clear and concise documentation that explains how developers can use the API to build their applications.

This includes understanding the audience for your documentation, what types of requests and responses they will be sending, and how the API operations support that.

One of the first steps in writing API documentation is to understand the basics of how APIs work. This includes learning about different types of requests and responses, what an endpoint is, and how resources are targeted on the back end.

It also helps to have a basic understanding of JSON and how to make simple API requests using tools like Postman or cURL. This can help you understand the syntax and structure of API requests, which is essential for writing accurate and effective documentation.

Another important aspect of writing API documentation is understanding the terminology used by developers. This can be challenging, as developers often use terms inconsistently. As a technical writer, it's important to be clear and consistent in your use of terminology, and to make sure that your documentation accurately reflects the purpose and functionality of the API.

For example, an API is a collection of operations, while a single endpoint is not an API. Understanding these distinctions can help you write documentation that is clear and easily understood by developers.

Open API (formerly known as Swagger Integration) is a standard for specifying APIs that can be incredibly useful for technical writers. Open API allows developers to create and maintain a standardized specification of their API, which can be used to generate server code and documentation.

This makes it much easier to create and maintain accurate and up-to-date documentation, as you can simply generate it from the Open API spec. Technical writers may not be responsible for creating the Open API spec, but it's important to understand how it works and how it can be used to create effective documentation.

Start writing API documentation

Writing API documentation is a collaborative process since the technical writer needs to collaborate with the development team.

To write effective API documentation, it's important to create clear, and comprehensive Getting Started guides and walkthroughs. These guides should explain how to get credentials, send authentication requests, and make basic requests to an endpoint.

They should also explain how to string multiple requests together to build a useful application. By following these steps and understanding the basics of APIs and Open API specs, you can write clear and effective API documentation that is easily understood by developers.

Here are the steps you should follow to create API documentation.

  1. Start with a clear outline: Before you start writing your API documentation, it's important to have a clear outline of the information that you want to include. This outline should identify the key endpoints, parameters, response types, and any other relevant information that users need to know to use the API effectively. A clear outline can help ensure that your documentation is comprehensive and well-organized, and can save time by ensuring that you don't miss any important details.
  2. Use clear and concise language: Good API documentation should be written in clear and concise language that is easily understandable by the intended audience. Use plain language, and avoid technical jargon or complex terms that might confuse or overwhelm the reader. Whenever possible, use examples and code samples to illustrate key concepts and make the documentation more engaging and easier to understand.
  3. Focus on the developer experience: When writing API documentation, it's important to keep the end-users in mind. Think about how the users will interact with the API and what information they need to get started. Consider including tutorials, code samples, and troubleshooting guides to help users get the most out of the API. By focusing on the developer experience, you can create documentation that is clear, comprehensive, and easy to use.
  4. Collaborate with developers: To write effective API documentation, it's important to collaborate closely with developers and other stakeholders. Work with API developers to ensure that the documentation accurately reflects the purpose and functionality of the API. Use their expertise to identify the key endpoints, parameters, and response types that need to be documented, and review code samples to ensure that the documentation is accurate and up-to-date.
  5. Review and update regularly: Finally, it's important to review and update your API documentation regularly to ensure that it remains accurate and up-to-date. APIs can change over time, and it's important to reflect those changes in the documentation. Set up a process to review and update the documentation on a regular basis, and work closely with developers and other stakeholders to identify any changes or updates that need to be made. By keeping your documentation up-to-date, you can ensure that users have the information they need to use the API effectively.

What should API documentation include?

The best way to understand API documentation is to look up some examples. One of the best out there is Stripe API Reference.

Let's take a look at this one - Creating a Price from Stripe docs. 

Creating a Price from Stripe docs
Source: stripe.com

I've highlighted the sections in the API docs. It starts with a description of what the endpoint does. On the right side, you can see code examples and the response body. The code examples may be different depending on the library the developer is using. A critical section is the one where an API writer describes the parameters.

If you check other examples, like Twilio, Sendgrid, you will find that these sections vary, but most of the time, you will find the following structure for API docs:

  • Resource description
  • Resource URL
  • Code examples
  • Endpoints and methods
  • Parameters
  • Request examples
  • Response example
  • ‍Status and error codes

‍

What are the types of API Documentation?

Understanding the types of API docs helps structure the content. You will find various categorizations, but most of the time, we split API documentation into three:

1. Reference

This is the backbone of the API documentation because it provides information about the structure, parameters, and return values for each function or method in an API.

The developers use this piece the most, so it gets the most attention. Thus, it needs to be spot on. More precisely, describe all the things. I cannot emphasize enough: all the endpoints and assets, resources, units, forms, as well as response codes and errors. Every single thing.

2. Conceptual

Check out SendGrid. As you can see, you have the API reference, and the Get Started path. Usually, the conceptual documents describe how it works, the resources, and how they interconnect. It describes the kinds of things you can do and summarize some common patterns.

Sendgrid for Developer
Source: sendgrid.com

Rather than just describing every function individually, conceptual documentation describes how APIs can be used to build applications. It also explains integrating multiple APIs into a single application (e.g., functions that work together).

These will typically include a tutorial or information about the API keys needed to authorize requests.

3. Tutorials

Tutorials provide step-by-step guides for how to do specific stuff with the APIs. There are usually detailed instructions on the use of each function call and parameter. When you want to point your users to particular use cases, tutorials are key to your documentation.

If you're structuring your API documentation, you should keep these three types in mind. You might only need to write references, but know that good API docs are more comprehensive.

Probably you have noticed that API documentation varies significantly between companies.

To set yourself up for success, no matter the structure you choose, try to solve and include these four points in your API documentation:

  1. What does a user need to submit to an endpoint to get back the exact data or perform a specific action
  2. What is the authentication requirements for accessing the resources
  3. What information is returned, and how should it be interpreted
  4. Try it out section

Which tool is best for API documentation?

There are many API documentation tools, from open source to commercially available. Some of the most popular tools for API documentation include:

  1. Swagger UI: Swagger UI is an open-source tool that allows you to generate interactive documentation for your API using an OpenAPI specification. Swagger UI offers a variety of customization options, making it a great choice for developers who want to create documentation that is tailored to their specific needs.
  2. Archbee is a cloud-based documentation platform that offers a variety of features for creating and managing API documentation. Archbee allows you to create and organize documentation using a hierarchical structure, making it easy to create nested pages and sections. The platform also offers collaboration tools, which allow multiple users to work on the same documentation simultaneously.
  3. Postman: Postman is a popular tool for API testing and documentation. It offers a built-in feature for generating documentation, which can be customized to suit your needs. Postman also offers a variety of collaboration features, making it easy for developers and technical writers to work together on API documentation.
  4. Redoc: Redoc is an open-source tool for creating high-quality API documentation. It allows you to generate interactive documentation from an OpenAPI specification, and offers a variety of customization options for styling and branding. Redoc also offers a live preview feature, which allows you to see how your documentation will look as you create it.
  5. Headless CMS platforms can also be a great tool for creating and managing API documentation. A headless CMS is a content management system that provides an API for accessing and managing content, without dictating how that content is presented to the end user. This makes it an ideal platform for creating and managing API documentation, as you can store your documentation as content in the CMS and then access it using the CMS's API.

Best practices and resources for API docs

Creating effective API documentation requires a focus on the user, a clear and consistent structure, and the use of examples and interactive documentation tools. It's also important to provide versioning and revision history, leverage existing resources, and gather feedback from users to continually improve the documentation over time. Here are some best practices and resources for API documentation:

  1. Use a consistent and clear structure: One of the most important aspects of API documentation is ensuring that it is organized and structured in a clear and consistent way. This means using a logical hierarchy, providing examples, and using a consistent tone and terminology throughout the documentation.
  2. Focus on the user: API documentation should be written with the end user in mind. This means using language that is easy to understand, providing examples that are relevant to the user's needs, and focusing on the tasks that the user will be trying to accomplish.
  3. Include examples and code snippets: Providing examples and code snippets can be incredibly helpful for users who are trying to understand how to use your API. Make sure that your examples are relevant to the user's needs and provide enough detail to be helpful.
  4. Use interactive documentation tools: Interactive documentation tools like Swagger UI, Postman, and ReadMe can make it much easier for users to understand how to use your API. These tools provide a user-friendly interface for exploring your API and can help to reduce confusion and errors.
  5. Provide versioning and revision history: As your API evolves, it's important to provide versioning and revision history features so that users can track changes and understand how to update their own applications to work with the latest version of your API.
  6. Leverage existing resources: There are many existing resources and tools that can be helpful when creating API documentation, including API style guides, documentation templates, and best practices guides. For example, the OpenAPI Specification provides a standardized format for describing APIs, while the Microsoft REST API Guidelines offer best practices for API design.
  7. Get feedback from users: Finally, it's important to get feedback from users on your API documentation. This can help you identify areas that are unclear or confusing and make improvements to the documentation over time. You can gather feedback through surveys, user testing, and other methods.

If you want to become an API writer, there are great resources around the web:

‍

Conclusion

In conclusion, API documentation is unique in several ways, but the most critical aspect is that it sells the product. It is crucial to pick the right tool and to know who owns the API documentation.

By following best practices for API documentation and using the right tools and resources, technical writers and developers can create documentation that is clear, concise, and easy to understand. Using this guide you will definitely learn how to write API documentation!

We have covered the basics of API documentation, including the different types of APIs, who typically writes API documentation, and the key elements of effective API documentation.

We have also provided some tips and best practices for creating API documentation, such as using a consistent and clear structure, providing examples and code snippets, and leveraging interactive documentation tools.

Whether you are a technical writer, developer, or product manager, understanding how to write effective API documentation is a valuable skill that can help you to create better APIs and improve the user experience for your customers.

‍

FAQ

Frequently Asked Questions

What is an API?
Expand FAQ

To make writing API documentation easier, you can use Archbee's collaborative documentation platform to streamline the writing process and ensure consistency. So, give it a go! Follow the practices and resources outlined in this article to create documentation that's super user-friendly, comprehensive, and crystal-clear, and ensure the success of your API.

API is an acronym for Application Programming Interface. It is a set of rules, protocols, and tools that allows different software applications to communicate with each other. APIs define how different software components should interact with each other, making it possible for developers to build complex applications that combine the functionality of multiple components.
What is the difference between API and REST API?
Expand Button

To write API documentation with examples, follow these steps: you must be sure that you understand the API, you must always define your audience, create a clear structure of the documentation you want to achieve, provide useful examples and according if necessary, use images as well, always use clear and concise language, last but not least - test the documentation.

The main difference between API and REST API is that REST API is a specific type of API that follows a set of conventions and principles, while API refers to a general concept of how different software components can interact with each other.
What are different types of API?
Expand Button

API documentation can be done by absolutely anyone, regardless of their programming skills or experience. However, technical writers most often create API documentation in collaboration with product or application developers. This collaboration ensures that the documentation is accurate, clear, and easy to understand, while providing guidance on how to interact with the API.

Main types of API include: SOAP (Simple Object Access Protocol), REST (Representational State Transfer) APIs, GraphQL APIs and Real-time APIs.
Who writes API documentation?
Expand Button
While you don't need to be a programmer to write API documentation, this task is typically done by technical writers, who work closely with developers to create and explain how to use the API. Depending on the organization, other stakeholders may also be involved in creating API documentation, such as product managers or project managers.
What does a technical writer need to know to write API documentation?
Expand Button
A technical writer needs to have an understanding of how APIs work and how to use the correct terminology to talk about them. This includes learning about different types of requests and responses, what an endpoint is, and how resources are targeted on the back end. Understanding the terminology used by developers and having a basic understanding of JSON and how to make simple API requests using tools like Postman or cURL are also important.

đź“– Table of contents

Answer questions instantly

Create and share documentation that answers questions instantly with Gen AI

Discover Archbee

Receive documentation and technical writing tips & trends — our newsletter

Join 5000+ people from around the world that receive a monthly edition of the Archbee Blog Newsletter.

Read more in

Documentation