Pattern: API Description

Which knowledge should be shared between an API provider and its clients? How should this knowledge be documented?


The final version of this pattern is featured in our book Patterns for API Design: Simplifying Integration with Loosely Coupled Message Exchanges.

Pattern: API Description

a.k.a. API Documentation, Explicit Service Contract

Context

A service provider has decided to expose one or more API operations in an API endpoint. Developers of clients (i.e., Web and mobile app developers implementing Frontend Integrations or the system integrators writing adapters for Backend Integrations) are not yet able to code service invocations and do not know what to expect in responses. Furthermore, supplemental interface descriptions are missing as well, including informal explanations of the meaning of the API operations (e.g., parameters in message representations, effects on application state in the API implementation) and related qualities (e.g., idempotency, transactionality).

Problem

Which knowledge should be shared between an API provider and its clients? How should this knowledge be documented?

More precisely:

  • How can API client and API provider make their agreement on the functional aspects of service invocation (e.g., data transfer representations and invocation prerequisites) explicit?
  • How can this functional information be amended with other technical specification elements (e.g., protocol headers, security policies, fault records) and business-level documentation (e.g., call semantics, API owner, billing information, support procedures, versioning)?

Forces

High-level forces to be resolved and balanced when defining shared knowledge in distributed systems include:

  • Interoperability (of clients and providers written for, and running on, different middleware platforms)
  • Consumability (including understandability, learnability, and simplicity)
  • Information hiding (of implementation details)
  • Extensibility and evolvability (as facets of general modifiability and maintainability)

Pattern forces are explained in depth in the book.

Solution

Create an API Description that defines request and response message structures, error reporting, and other relevant parts of the technical knowledge to be shared between provider and client. In addition to static and structural information, also cover dynamic or behavioral aspects, including invocation sequences, pre- and postconditions, and invariants. Complement the syntactical interface description with quality management policies as well as semantic specifications and organizational information.

Example

The “Template for Elaborate API Descriptions” in Figure 3 covers both business information as as well as functional-technical API design concerns.

Figure 3: Template for Elaborate API Descriptions

While the template fits on one presentation slide or document page, API Descriptions that follow this template probably will require more space. In practice, such API descriptions are often made available via developer portals, project wikis, or service documentation websites.

Are you missing implementation hints? Our papers publications provide them (for selected patterns).

Consequences

The resolution of pattern forces and other consequences are discussed in our book.

Known Uses

The Microservices Canvas template proposed by C. Richardson creates Elaborate Descriptions when filled out completely. The template includes implementation information, service invocation relationships, and events produced/subscribed to.

Agile Modeling suggests an informal contract model that can be seen as medium verbose API Description.

Many concrete examples of API Descriptions exist. Here we include Terravis, which uses annotated WSDL according to Lübke and Lessen (2016); so does the Dynamic Interface described in Brandner et al. (2004). Developer portals and Do-It-Yourself (DIY) service registries/repositories make these and complementing business/quality policy information available to API users (e.g., frontend and integration developers). A Swiss software vendor specializing on the insurance industry defines its own API documentation format in its internal REST API Design Guidelines.

Technical API description notations exist in many forms for various distributed computing and middleware platforms:

On a broader level, the following notations and assets also qualify as known uses of this pattern:

  • Unified Service Description Language (USDL) is a more comprehensive approach that adds metadata and semantic information to the contract, see this W3C report.
  • The SOYA framework implements the SOAP Service Description Language (SSDL) specification in C# and on top of Windows Communication Foundation (WCF).
  • In the finance industry, SWIFT uses XML (and WSDL/SOAP) as technical interface description language. An example is the Alliance Access messaging interface. SWIFT also standardizes message exchanges and has elaborate SLAs, starting with a master SLA refined by those for individual services.

SOA maturity levels can help with the decision between minimal and elaborate descriptions, supported by the notations and assets listed above.

More Information

Related Patterns

Depending on mission criticality and market dynamics, an API Description be completed with a Service Level Agreement to specify quality goals – and the consequences of not meeting them. Version information and evolution strategies can be included (see for instance Version Identifier and Two in Production patterns).

Service Descriptor in Daigneau (2011) and Interface Description in Voelter, Kircher, and Zdun (2004) cover the technical part of the API Description.

Other Sources

An online API Stylebook collects and references related documentation advice in a dedicated design topic. Recipe 14.1 in the RESTful Web Services Cookbook by Allamaraju (2010) discusses how to document RESTful Web services. The Engagement Perspective of Zimmermann, Tomlinson, and Peuser (2003) collects WSDL and SOAP best practices; much of the given advice also applies to other API contract syntaxes. See for instance an OOPSLA 2008 tutorial. The Australian Digital Transformation Office (DTO) has a best practice rule “document your API” that lists examples of good API documentation.

The notion of Design-by-Contract was established by B. Meyer in Meyer (1997) in the context of object-oriented software engineering; his advice can also be adopted when defining remote API contracts.

The specific role of data in interface contracts is explained in “Data on the Outside vs. Data on the Inside” by P. Helland Helland (2005).

The practice collection Design Practice Repository (DPR) features a stepwise service design activity and an API Description artifact Zimmermann and Stocker (2021).

References

Allamaraju, Subbu. 2010. RESTful Web Services Cookbook. O’Reilly.
Brandner, Michael, Michael Craes, Frank Oellermann, and Olaf Zimmermann. 2004. “Web Services-Oriented Architecture in Production in the Finance Industry.” Informatik-Spektrum 27 (2): 136–45. https://doi.org/10.1007/s00287-004-0380-2.
Daigneau, Robert. 2011. Service Design Patterns: Fundamental Design Solutions for SOAP/WSDL and RESTful Web Services. Addison-Wesley.
Erl, Thomas, Benjamin Carlyle, Cesare Pautasso, and Raj Balasubramanian. 2013. SOA with REST - Principles, Patterns and Constraints for Building Enterprise Solutions with REST. Prentice Hall.
Evans, Eric. 2003. Domain-Driven Design: Tacking Complexity in the Heart of Software. Addison-Wesley.
Helland, Pat. 2005. “Data on the Outside Versus Data on the Inside.” In Proc. Second Biennial Conference on Innovative Data Systems Research (CIDR), 144–53. http://cidrdb.org/cidr2005/papers/P12.pdf.
Lübke, Daniel, and Tammo van Lessen. 2016. “Modeling Test Cases in BPMN for Behavior-Driven Development.” IEEE Software 33 (5): 15–21. https://doi.org/10.1109/MS.2016.117.
Meyer, Bertrand. 1997. Object-Oriented Software Construction. 2nd ed. Prentice-Hall.
Van Heesch, Uwe, Theo Theunissen, Olaf Zimmermann, and Uwe Zdun. 2017. “Software Specification and Documentation in Continuous Software Development: A Focus Group Report.” In Proceedings of the 22nd European Conference on Pattern Languages of Programs, 35:1–13. EuroPLoP ’17. New York, NY, USA: ACM. https://doi.org/10.1145/3147704.3147742.
Voelter, Markus, Michael Kircher, and Uwe Zdun. 2004. Remoting Patterns - Foundations of Enterprise, Internet, and Realtime Distributed Object Middleware. Wiley.
Zimmermann, Olaf. 2015. “Architectural Refactoring: A Task-Centric View on Software Evolution.” IEEE Software 32 (2): 26–29. https://doi.org/10.1109/MS.2015.37.
———. 2017. “Microservices Tenets.” Comput. Sci. 32 (3-4): 301–10. https://doi.org/10.1007/s00450-016-0337-0.
Zimmermann, Olaf, and Mirko Stocker. 2021. Design Practice Reference - Guides and Templates to Craft Quality Software in Style. LeanPub. https://leanpub.com/dpr.
Zimmermann, Olaf, Mark Tomlinson, and Stefan Peuser. 2003. Perspectives on Web Services: Applying SOAP, WSDL and UDDI to Real-World Projects. Springer.