APIドキュメント
APIドキュメントとは?
APIドキュメントとは、APIの利用方法や統合方法を人が理解しやすい形でまとめた説明資料です。
APIドキュメントには、利用可能なエンドポイント、メソッド、リソース、認証プロトコル、パラメーター、ヘッダーに関する詳細情報に加え、一般的なリクエストとレスポンスの例が含まれます。質の高いAPIドキュメントは、プライベートAPI、パートナーAPI、パブリックAPIの開発者体験を向上させるだけでなく、それぞれのAPIに固有の価値ももたらします。たとえば、プライベートAPIのドキュメントはチーム間のコラボレーションを促進し、パブリックAPIのドキュメントはリーダーがサードパーティAPIの想定ユースケースを理解し、自社のビジネス目標の達成に役立つかどうかを判断しやすくします。APIドキュメントを重視するチームでは、APIの採用率向上、サポートチケットの削減、さらにパブリックAPIの場合は収益の増加といった成果が見られる傾向があります。
ここではまず、APIドキュメントがAPIファーストの世界で果たす役割について説明します。次に、APIドキュメントを構成する主要な要素とベストプラクティスを紹介します。最後に、Postman APIプラットフォームがどのように提供者によるAPIドキュメント作成を支援し、利用者の成功につなげているのかを見ていきます。
なぜAPIファーストの世界でAPIドキュメントが重要なのか
APIファーストとは、APIを通じて提供される社内外のサービスを組み合わせてアプリケーションを設計、構築する開発モデルです。このアプローチにより、複雑に連携するマイクロサービス群を基盤とした高性能なアプリケーションを構築できるだけでなく、APIをサードパーティの利用者向けに有料の製品として提供するAPI-as-a-Product戦略も支援できます。そのため、多くの組織がAPIファースト戦略を採用し、ビジネス目標の達成につながる高品質なAPIを体系的に開発しています。
APIドキュメントは、プライベートAPIとパブリックAPIのどちらにおいても、その成功を支える重要な役割を果たします。たとえば、社内向けAPIのドキュメントはチーム間のコラボレーションを促進し、コードの重複を減らすとともに、新入社員のオンボーディングを効率化します。これにより、すべてのチームが優れたソフトウェアをユーザーに提供するという共通の目標に向けて、効率的に業務を進められるようになります。一方、パブリックAPIのドキュメントは、利用を検討している利用者がAPIを理解し、実際に試せるようにすることで、採用の拡大、ひいては収益の向上につながります。実際、Postmanの『State of the API Report』では、サードパーティAPIとの統合を判断する際に、リーダーが重視する要素の1つとしてドキュメントが上位4項目に挙げられています。
代表的なAPIドキュメントの種類
APIドキュメントにはさまざまな種類があり、それぞれが利用者によるAPIの効果的な活用を支援する重要な役割を担っています。代表的なものとして、次の4種類があります。
- リファレンスドキュメント:一般的に、各エンドポイントのメソッド、パラメーター、サポートされているデータの型などの詳細情報を提供します。また、それぞれのエンドポイントが何を実行するためのものかを、わかりやすい言葉で説明します。
- サンプルとコードサンプル:一般的なAPIリクエストとレスポンスの例を提供します。複数のプログラミング言語でサンプルが用意されることも多く、利用者がAPIの動作や期待される結果を理解するのに役立ちます。
- リリースノート:新機能、バグ修正、セキュリティパッチなど、APIに加えられた重要な変更に関する情報を提供します。変更内容によっては利用者自身のコードベースに影響を与える可能性があるため、リリースノートは重要な情報源となります。
- チュートリアル:APIの利用方法を段階的に説明する形式のドキュメントです。多くの場合、APIがサポートする特定のユースケースに焦点を当てており、認証など利用開始時に必要となる一般的なワークフローについても解説します。
PostmanでビジュアルなAPIワークフローを活用する方法
APIワークフローは、一連のAPIがどのように連携して動作するのかを開発者が理解するのに役立ちます。Postmanでは、Flowsによってワークフローを中心としたAPIの理解を実現できます。APIコールをオーケストレーションするコードを記述する代わりに、ビジュアルキャンバス上でワークフローを構築できます。リクエスト同士がどのようにつながっているか、データがどのように流れるか、レスポンスに応じてロジックがどのように分岐するかを視覚的に確認できます。
詳細は、「FlowsのためのPostmanベストプラクティス」をご覧ください。
What should be included when creating API documentation?
Every API is different and therefore requires documentation that is tailor-made for its consumers. Nevertheless, the following components can serve as an initial checklist for creating high-quality API documentation:
APIドキュメントには何を含めるべきか
APIごとに特性が異なるため、利用者のニーズに合わせて作成されたドキュメントが必要です。それでも、高品質なAPIドキュメントを作成する際の出発点として、以下の項目をチェックリストとして活用できます。
認証手順
認証はAPIのデータを安全に保護するうえで役立ち、新しいAPIを利用する開発者が最初に越えるべきハードルです。APIの認証プロセスが難しすぎたり、十分に文書化されていなかったりすると、開発者は不満を感じ、別のAPIを試す可能性があります。そのため、APIドキュメントでは、利用できる認証方法を明確に説明し、認証情報の取得方法と使用方法を手順ごとに詳しく示す必要があります。
すべてのエンドポイント、オペレーション、リソースに関する詳細情報
APIドキュメントでは、すべてのAPIエンドポイントとオペレーションについて、パラメーター、ヘッダー、リクエストボディ、レスポンスボディを含む包括的な情報を提供する必要があります。また、関連するデータモデルについても、必須属性やデフォルト値、最小値、最大値を含めて詳しく説明する必要があります。こうした情報によって、考えられるあらゆるユースケースを網羅できるようになり、利用者はエラーが発生しやすい複雑なリクエストも正確に構築できるようになります。
一般的なリクエストとレスポンスの例
例は、利用者がさまざまな条件下でのエンドポイントの動作を理解するのに役立つため、効果的なAPIドキュメントに欠かせない要素です。提供者は、複数のクライアント言語によるリクエスト例に加え、レスポンス例も掲載する必要があります。これにより、利用者は発生した問題のトラブルシューティングを行いやすくなります。また、例は特定のワークフローで必要となる一連のAPIコールを新規ユーザーに案内する際にも役立ちます。これにより、APIが高度なユースケースをどのようにサポートできるのかを理解するための重要な知見が得られます。
利用規約
パブリックAPIのドキュメントには、利用規約を含める必要があります。利用規約は、利用者によるAPIのデータや機能の不正利用を防ぐための法的契約です。また、一定期間内に利用者が実行できるAPIコール数を定めるレート制限に関する情報も記載する必要があります。エンドユーザー向けサービスの停止につながる可能性があります。レート制限は、サービス拒否(DoS)攻撃や、APIのパフォーマンスに悪影響を及ぼすその他のアクティビティからAPIを保護するのに役立ちます。レート制限を超過した利用者は、一時的に追加のAPIコールを実行できなくなり、その結果、エンドユーザー向けサービスの停止につながる可能性があります。
- Understand the API: Anyone who is writing API documentation needs to not only understand the API's purpose, but also be familiar with its endpoints, methods, parameters, accepted data types, and authentication mechanisms. This will help ensure that the documentation is accurate and complete.
- Know your audience: API documentation is consulted by a wide range of audiences that may have different levels of technical knowledge. It's therefore important to identify your primary audience—and understand their needs—to ensure your documentation is useful.
- Provide detailed instructions for the most common use cases: While you should strive to thoroughly document the API's complete functionality, you should pay special attention to the most common use cases. Additional details, such as code samples and example requests, will help consumers get up and running with these use cases quickly.
- Review, test, and verify the documentation: Everyone makes mistakes, so it's critical to thoroughly test your documentation before publishing it. This process should involve a thorough walk-through of every use case and request, as well as an additional review by a stakeholder who was not directly involved in the documentation writing process.
- Continuously update the documentation: APIs evolve quickly, and outdated documentation can confuse consumers and erode their trust. It's therefore essential that you methodically review your documentation whenever you ship new code—and make updates as necessary.
APIドキュメントの書き方
APIドキュメントの作成は、APIの機能に対する深い理解、利用者への共感、そして継続的に改善していく姿勢が求められる複数のステップからなるプロセスです。効果的なAPIドキュメントを作成するために、次のポイントを押さえましょう。
APIドキュメント作成のベストプラクティス
APIドキュメントは利用者に大きな影響を与える重要な成果物であり、その品質はAPI全体の成功に直結します。そのため、APIドキュメントを作成する際は、次のベストプラクティスに従うことが重要です。
魅力的なストーリーを伝える
すべてのAPIは、提供者と利用者それぞれのソフトウェアエコシステムの中で独自の役割を担っており、APIドキュメントにはその価値や役割を伝える重要な役目があります。ドキュメントを読む人は、そのAPIが誰のために作られたものなのか、どのように利用できるのか、そしてどのように目標達成に役立つのかを理解できる必要があります。こうした「全体像」を示すことで、より技術的な実装の詳細を理解するための重要な背景情報が提供されます。これは、開発者がAPIの可能性や活用方法を理解していくうえで役立ちます。
ドキュメントを常に最新の状態に保つ
多くのAPI開発チームは、週に何度もコード変更をリリースしています。そのため、ドキュメントが実際のAPIの状態とずれてしまうリスクがあります。特に、更新内容に後方互換性がない場合、古いドキュメントは利用者の信頼を損なう原因になります。そのため、ドキュメントの更新プロセスを仕組み化し、本番環境で稼働しているAPIの最新の状態を常に反映できるようにすることが重要です。また、APIのリソースや機能に対するすべての変更を時系列で記録する変更ログにも、更新内容を記録する必要があります。
What are some examples of API documentation?
Postman's Public API Network is a global, centralized API catalog, where producers can share their APIs and API documentation with a community of over 40 million developers. Teams that publish their API documentation on the Public API Network can include detailed descriptions and tutorials, example requests and responses, and environment variables, which can increase API adoption and reduce ticket volumes. Some teams that have published excellent API documentation in the Public API Network include Stripe, Notion, PayPal, Amplitude, Salesforce, and DoorDash, and this list just scratches the surface. Explore the Public API Network to see more.
Learn more with Postman Academy's API documentation course
Why use Postman for API documentation?
The Postman API Platform includes several features that enable teams to make effective documentation a core part of their API workflow. With Postman, you can:
- Automatically generate API documentation: Postman enables users to automatically generate API documentation for any OpenAPI 3.0 definition, as well as for any collection they create. Postman API documentation includes information about each path, operation, and data model, while collection documentation includes sample code in various client languages, as well as key-value pairs for request parameters, headers, and bodies.
- Keep API documentation up-to-date: Postman automatically updates documentation to reflect the latest changes to a definition or collection, which helps teams ensure that their consumers always have the most up-to-date information about their API.
- Enhance collection documentation with more details: API producers can add more information to collection documentation, such as descriptions, text, tables, and images, in the visual Postman editor or classic Markdown editor. These details provide additional context that can help consumers better understand an endpoint's purpose or functionality.
- Use variables to connect documentation to specific environments: Postman users can create and save variable values for specific environments—and share those environments as part of their documentation. This can be especially useful for teams who want to offer a testing environment to go along with their API's documentation, which enables potential consumers to experiment with the API without incurring costs or having to go through the full authentication process.
- Publish documentation alongside other public API artifacts: API producers can publish documentation alongside their workspaces and collections in the Postman API Network, which enables consumers to more easily discover, explore, and begin working with the API. Producers can also publish their documentation to public domains.
APIドキュメントにPostmanを活用する理由
Postman API Platformには、効果的なドキュメント作成をAPIワークフローの中核に組み込むためのさまざまな機能が備わっています。Postmanを使えば、次のようなことが可能になります。