White Paper-The Definitive Guide To Creating API Documentation
White Paper-The Definitive Guide To Creating API Documentation
Introduction 1
Best Practice 1: Follow a Standard Template or Outline Reference Pages 2
Best Practice 2: Use a Terse, Factual Writing Style 5
Best Practice 3: Provide Complete Information About Each API Component 6
Best Practice 4: Document All Error Messages 10
Best Practice 5: Provide Working Code Snippets for Each Method 11
Best Practice 6: Provide Flowcharts Showing Common Use Cases 12
Best Practice 7: Provide Sample Programs Demonstrating Common Use Cases 14
Best Practice 8: Provide a “Getting Started” Guide 15
Best Practice 9: Provide Performance and Tuning Information 16
Best Practice 10: Provide a Contact Person for Your API 17
Summary 18
Appendix: Sample API Reference Page 19
About the Author 21
Most of the principles that apply to technical writing for other products, such as GUI-based
applications and end-user applications, apply to documenting APIs as well. But there are some major
differences that often elude technical writers moving into this area of technical writing. This white
paper covers ten best practices for writers to keep in mind:
2. Use a terse, factual writing style. Sentence fragments are desirable. Avoid
adjectives and adverbs.
4. List all error messages alphabetically, specify the level of the message, and
provide suggested workarounds and solutions.
5. Provide working code snippets for each method, function, and resource. You
don’t need complete examples, but show a common use of that element.
6. Provide flow charts showing the sequence of the most commonly used
methods for common use cases.
Most APIs use a very similar template or organizational structure for API components, including
methods, functions, or resources. These categories of API elements each perform a single operation
or task, such as opening a file, starting an interactive session, and logging into a computer system.
C-type languages use the terms “method” or “function” interchangeably. The Java programming
language uses the term “method.” Web service APIs use the term “resource.” But all three names are
functionally the same and are documented in much the same way. You should follow the standard
template or outline for organizing reference pages.
Note: In this white paper, the term “method” is used to generically refer to all three terms.
Syntax
Display the actual method call used in the code.
Description
More detailed information about the method; information developers need to know to call the method.
Note: For all of the following sections, if the section doesn’t apply to the specific method or has no
elements, such as no return value or has no related methods, explicitly state that by using a term
such as “None” or “Not applicable.” This tells developers that you didn’t forget to put information in
those sections.
Parameters
List all of the parameters here, in the order they appear in the syntax. You can either use a pseudo-list
format as the following or put the information into a table, shown after the pseudo-list.
Return Value
Value returned by the method:
Examples
A short code snippet here, with explanation, showing use of this method.
Errors
List the errors that can be returned for this method, with the level of error and the recommended
workaround or solution.
Notes
Any supplemental, “nice to know” information.
See Also
Cross-references to related methods.
• Be factual.
• Sentence fragments are acceptable. For example, when you are describing what a
specific method does, it is acceptable and desirable to use a sentence fragment. For
example, for a sessionTerm method, your brief description would read, “Ends a session
and closes all open files.”
• Avoid adjectives and adverbs. Developers are very factual. They don’t want to read how
fast something works, how easy it is to use, etc. Developers will quickly lose confidence
and trust in your documentation if you use adjectives and adverbs.
• Be alert for homegrown terms that are used by a specific developer or team of
developers that are not industry-standard. If you encounter a jargon-like term that you
don’t recognize, ask your developer or team if that is a standard term in your industry.
If it isn’t, push to determine the correct standard term. If it is a new term but your
team insists it should be used, define it the first time you use it in your documentation.
(Optionally, consider creating a glossary where you define all of the new terms used in
your API.)
• Often method names are formed by concatenating many words, which leads to very
long terms. Accept these as is. Do NOT make up your own terms, because you think
the names are too long or break awkwardly in printed or PDF output.
Method_Name
The Method_Name should be your heading at the top of a reference page. Most API documentation
does not include “Method” after the Method_Name. Each method is documented starting on a new
page. This makes it easy for developers to view or print the complete reference information for a
single method. It is confusing if you start a new section for a new method partway through a page for
printed documentation. For online help, having each reference page as a separate topic is much
easier for developers to read and find the information they need.
Following the Method_Name, provide a brief description of what the method does. For example:
Logs into a previously created session, where a session is an interactive sequence of user requests
and system responses.
Syntax
In this section, you document the complete syntax for the method, exactly as it is used in the code.
For example:
STATUS SessionLogin(
SESSION_HANDLE session,
const STRING username,
const STRING password,
UINT32 timeout);
The “STATUS” that starts the syntax is the status code returned by this method. Many methods
return a status code or value that can be used to determine what the program does next or some
alphanumeric value that will be used to calculate some math result or data to be stored or otherwise
acted on.
Next is the method name, SessionLogin, followed by an open parenthesis. Then, all the parameters
preceded by their data types, separated by commas. The following table shows the relationship
between the parameter and its data type. You do not show the syntax this way in your
documentation.
The syntax is closed with a closing parenthesis followed by a semicolon. This is standard coding in
many programming languages.
Description
In this section, provide more detailed information about the method. This should be essential
information. As a guideline, if 90% of the developers need to know this information or will find it
useful, include the information in this section. For example:
An application can maintain multiple sessions. You can have up to 8 sessions per application. You
need to use the same API User name for each (you will get an ERR_USERNAME_NOT_VALID error
if you do not).
Parameters
In this section, list all the parameters, in the order they appear in the syntax. For example:
session - SESSION_HANDLE
username - STRING
The API User name defined in the TPM. The TPM must have Topic entitlement rights (publish or
subscribe) associated with this API User name before you can publish or subscribe to messages on
those Topics.
password - STRING
The password for the API User in string format. The secure value will be put into the securityContext
structure.
timeout - UINT32
The length of time that a login will be attempted before failure. This value is in milliseconds. A timeout
of 0 means the login attempt will never timeout, and will continue to retry to connect should the initial
connect attempt fail.
Return Value
In this section, if the method returns a value, you document that value in the code and what the data
type is. Depending on the number of return values, you might need to document all of the possible
return values. If the method does not return a value, enter “None.” For example:
STATUS - If the function succeeds, then OK is returned; otherwise, one of the status codes listed
in the ERRORS section is returned.
Examples
In this section, you provide a small code snippet that shows a typical use or call of the specific
method being documented. Developers often copy these code snippets into the code they are writing
and customize as needed for their application. For example:
Errors
In this section, you list all possible error messages that can be returned by a method, in alphabetical
order, with the recommended solution or workaround. For example:
ERR_NETWORK_WRITE – A generic network error. Check the client log for more information.
ERR_NULL_PASSWORD – You didn’t supply a password. Enter a password as described above
and re-run your application.
ERR_NULL_USERNAME – You didn’t supply a username. Enter a userName as described above
and re-run your application.
ERR_USER_NOT_LOGGED_IN – You attempted to use a session without logging in first.
Notes
In this section, you include any supplemental, “nice to know” information. This is information that
probably only will be used by 15% of the developers or used 15% of the time. For example:
Before calling SessionLogin, you will need your API User name and password.
When your application is finished processing all messages, call SessionTerm to end the established
session.
See Also
In this section, you provide hyperlinked cross-references to all of the related methods for the method
being documented. For example:
SessionLogin
SessionTerm
ERR_NETWORK_WRITE – A generic network error. Check the client log for more information.
ERR_NULL_PASSWORD – You didn’t supply a password. Enter a password as described above
and re-run your application.
Tip: Often an error message can be returned for multiple methods. If your authoring tool provides
snippets capability, consider making an error message that is returned for many methods into a
reusable snippet that you call as needed. This will make maintenance of the description for an error
message much easier.
APIs often have many methods in them, having several hundred methods is common. However, the
rule that 85% of your users will only use 15% of your product applies to APIs as well. The challenge
for API users is to determine which methods need to be used all or most of the time vs. which are
only used occasionally or rarely. One way of showing the most commonly used methods is to provide
flowcharts for the most common use cases, showing the methods used in those use cases and the
order they should be called.
For example, the following flowchart from an API documentation set shows how to log into a system:
This flowchart is very helpful to developers, because it shows the required methods to call to log into
a system and what order to call them, as well as some optional methods that might be helpful. Note
the brief but concise descriptions of what each method does or what operation is performed at each
step.
• Sample programs should show common or typical use cases for your API.
• They should be complete and run with no errors or warnings.
• You should provide readme files explaining what the program does, how to run it, any
necessary input data, and expected results.
The following example shows the outline for a “Getting Started Guide” that shows developers how to
speech-enable an application:
• What effect the default value has and why that value was chosen.
• Guidance on setting the default value to other values in the valid value range according
to your specific needs. For example, if you need more data throughput, change
parameter x to a value such as the following: n. Conversely, if you need less or more
latency, change the value of parameter x to the following: m. Developers can and should
experiment around the recommended setting for a specific scenario once they set the
value to your recommended setting. But your recommendation, based on your own
testing in-house, saves your users from spending a lot of unnecessary time guessing
what values to try to achieve a desired result.
For example, you might have a PUB_BW_LIMIT (publisher maximum bandwidth), tuning parameter
with the following description:
PUB_BW_LIMIT - The maximum bandwidth, in Mbps, of the publisher. The default value is 100 (100
Mbps). The minimum value is 0, which disables the limit. Use this parameter if you noticed (or your
sys-admin told you) that your publisher was flooding the network. You might use it to limit a
particularly fast publisher to half the link (500) so that it doesn’t overwhelm the subscriber.
• Your users are probably software developers themselves, and very computer-literate.
Their questions might overwhelm tech support people, who might be inexperienced or
don’t have deep programming backgrounds.
• Often, developers need to submit log files, screenshots of the run of an application, or
other information that is cumbersome at best to communicate by telephone.
Set up a special email account for your API that is directed either to a high-level technical support
person who is fluent with your API(s) or a developer on your team who is designated to respond to
customer queries. Instead of the common pattern of “[email protected]”, create an
account, such as “[email protected]” and have all queries go to the
designated technical support person or designated developer.
If you are documenting internal APIs for internal use only, consider specifying the actual developer
who is assigned to support internal users of that API. In this case, your email link would go directly to
that developer, [email protected].
Publish a short topic named something like “Technical Support” that you include in your
documentation after your content topics/chapters. Suggested content:
Providing an email link to a knowledgeable technical support or designated API developer benefits
both your company and customers. Your company resolves customer issues faster, thus saving time
and money. Your customers get their questions resolved faster and more accurately. Both your
company and customer get increased customer satisfaction.
2. Use a terse, factual writing style. Sentence fragments are desirable. Avoid adjectives and
adverbs.
4. List all error messages alphabetically, specify the level of the message, and provide
suggested workarounds and solutions.
5. Provide a working code snippet that shows a common use for each method.
6. Show the sequence of the most commonly used methods for common use cases.
7. Provide full, working sample programs that demonstrate common use cases for your API.
8. Develop some common use cases and provide a “Getting Started” guide that documents
how to program for them.
10. Designate a contact person, who is fluent with your API, as a resource for your users, not
just a generic “[email protected]” mailing address.
By implementing these best practices, you will provide documentation that not only meets the needs
and expectations of your users but will substantially help them get started quickly in learning and
using your API to solve their technical challenges.
Syntax
STATUS SessionLogin(
SESSION_HANDLE session,
const STRING username,
const STRING password,
UINT32 timeout);
Description
An application can maintain multiple sessions. You can have up to 8 sessions per application. You
need to use the same API User name for each (you will get an ERR_USERNAME_NOT_VALID error
if you do not).
Parameters
session - SESSION_HANDLE
Input. A handle to the session.
username - STRING
Input. The API User name defined in the host system.
password - STRING
Input. The password for the API User in string format.
timeout - UINT32
Input. The length of time that a login will be attempted before failure. This value is in milliseconds. A
timeout of 0 means the login attempt will never timeout, and will continue to retry to connect should
the initial connect attempt fail.
Return Value
STATUS - If the function succeeds, then OK is returned, otherwise one of the status codes listed in
the ERRORS section is returned.
Errors
ERR_BAD_NETWORK_CONFIG – Error setting up the SSL channel.
ERR_NULL_PASSWORD – You didn’t supply a password. Enter a password as described above
and re-run your application.
ERR_NULL_USERNAME – You didn’t supply a username. Enter a userName as described above
and re-run your application.
ERR_USER_NOT_LOGGED_IN – You attempted to use a session without logging in first.
Notes
Before calling SessionLogin, you will need your API User name and password.
When your application is finished processing all messages, call SessionTerm to end the established
session.
Example
returnCode = SessionLogin(sess, DFT_USERNAME, DFT_PASSWORD,5000);
See Also
SessionLogin
SessionTerm
Flare Webinars:
• “Using MadCap Flare to Support Your International Content Strategy”
http://www.madcapsoftware.com/webinars/using-madcap-flare-to-support-your-interna-
tionalstrategy/
• “A Case Study in Translation Management – How to Reduce Costs by 90% While Enabling
New Markets”
http://www.madcapsoftware.com/webinars/case-study-in-translation-management-how-
toreduce-cost-by-while-enabling-new-markets/
• “Case Study: How Hewlett Packard Enterprise Leverages MadCap Lingo to Reduce
Translation Costs by 50%”
https://www.madcapsoftware.com/webinars/case-study-hewlett-packard-
enterpriseleverages-madcap-lingo-reduce-translation-costs/
23