API Documentation "Almost" Done Right
API documentation is more than just a list of what your interface can do. It tells a story. See what you should keep in mind when writing your docs.
Join the DZone community and get the full member experience.Join For Free
i've integrated with, and also built, not a small number of apis in my years while working on different web services, defining restful apis, and more.
over the course of integrating with and researching a bunch of apis, i've looked at the documentation of the apis i have worked with. the sad fact is, most of it is terrible . from poorly documented endpoints to a lack of code samples, i've spent hours pinging endpoints trying to get a request right because the documentation was so bad.
i've been working on a project where i've had to design — and document — a brand new api. the api is restful and exposes services out to a number of clients. pretty standard stuff.
as part of this project, i needed a way to document how we were designing the api architecture — all the endpoints, data models, all that. in our case, the api hasn't even been built yet - we’re designing it completely, then building it.
"great api documentation is essential," many people exclaim. so, you fire up your favorite api definition editor and start writing docs. you learn what raml is and how to format it properly. you agonize over the url paths, verbs, response codes, and payload definitions. finally, you reach that glorious moment: "documentation is done! whew!" not quite.
while it is an important step to create api reference documentation , focusing only on these docs can cause you to miss the hidden value that api documentation can bring to your customers and your team.
the hidden value of api documentation
api documentation tells the story of your api. from the getting started guide to core concepts and examples, your api documentation informs the audience about how you see their problem. as we know, we can solve problems using a variety of approaches and points of view.
your documentation tells me your story: how you see the world, my problems, and your solution to those problems.
api documentation is the primary communication medium between api provider and consumer. unless the api is open source, you will likely never see the source code behind it. therefore, the only thing that developers consuming your api have is your documentation. without clear and complete documentation, developers will struggle to use your api.
api documentation validates api design prior to implementation. by including documentation as part of the process and including technical writers during the design and development process, api design flaws can be spotted before coding has been completed — when changes can still be made easily and with minimal impact.
beyond api reference documentation
we use the term "api documentation" as if there is only one kind of documentation. yes, you need to deliver a great api reference for developers. tools such as swagger, raml, and blueprint are just a few of the formats available to help build them. however, complete api documentation requires more than just your api reference in html or pdf form. it requires looking at the marketing, development, and customer support aspects of documentation as well.
api documentation categories
as you see, it takes more than just generating an api reference to fully document your api. let's examine each of the options available to help compose your complete set of api documentation.
marketing-focused api documentation
features and discovery : provides an overview of the api, addressing concerns such as benefits, capabilities, and pricing of your api to qualify prospects. this may include marketing content for developers and key decision makers as well as automated discovery through formats such as apis.json.
case studies and examples : case studies highlight applications that have been built using your api. it is also useful for sharing usage of your api by applications that have been internally deployed and are therefore not generally not accessible. you may wish to consider providing examples and reference applications to demonstrate some of your api’s capabilities prior to developer sign-up.
development-focused api documentation
reference docs : provides a reference for each api endpoint to developers, including details on the url, http verb(s) supported, response codes, and data formats. developers use this documentation when starting to consume api endpoints whether for the first or the tenth time. while some developers may use reference documentation to become acquainted with the api product, it is most often used for exploration, development, and troubleshooting. this is where swagger, raml, and blueprint formats are used to generate documentation from an api definition.
guides and concepts : as an api consumer, the most difficult part of using an api is the initial learning curve. guides offer help with learning an api's concepts and vocabulary during this critical stage. they also provide step-by-step guides for implementing common use cases. combined with links to reference docs sprinkled throughout, developers are able to get started quickly and with confidence.
support-focused api documentation
problem/resolution : sometimes developers need a little help when consuming your api. documentation that helps developers troubleshoot error response codes can ease the burden on your developers and support staff. in addition, help pages and faqs can guide new and experienced developers toward a better understanding of your api and proper usage patterns.
internal docs : for those instances when developers need more assistance with your api, it is important to have internal assets to help your support team. don't forget to create and maintain internal design documentation, including diagrams and code comments, which go a long way to debug difficult issues.
putting it all together
there are a variety of online restful api documentation types beyond the typical reference documentation style we see today. each one serves a different purpose to support the api both internally and externally. you will need to mix and match them, depending on the purpose of your api, to create a complete set of documentation. be sure to select the ones that support your developers, your team, and the story your api tells.
Published at DZone with permission of Guy Levin, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.