-
Notifications
You must be signed in to change notification settings - Fork 7
6. API Documentation
Contract-First Design is a software development approach that revolves around contracts—formal definitions of interfaces and messages exchanged between systems. In this approach, the API or service structure is precisely defined before any code is written. These contracts usually include:
- Inputs and outputs
- Data types and their structure
- Validation rules
- Possible errors and error messages
Simply put, in Contract-First Design, the contract between systems is designed first, and the actual code is implemented afterwards. This is the opposite of Code-First Design, where code is written first and the API is generated based on it.
- Clarity and transparency: Everything is defined in the contract before development begins.
- Reduced inconsistencies: Different systems or teams can work independently based on a fixed contract.
- Early testing: Contracts allow for creating mock APIs, enabling testing and simulation before implementing the real logic.
- Automatic documentation: Contracts can be used to generate API documentation, eliminating the need for separate documentation.
- Parallel team development: Teams can work simultaneously without needing access to each other’s code.
In the Horizon project, we work with a distributed and modular system, where different components must interact accurately and reliably. The main reasons we adopt Contract-First Design in Horizon are:
- Team coordination: Each team can work on its own service without waiting for other parts to be completed.
- API stability: Once the contract is defined, unexpected changes are minimized, reducing future issues.
- Facilitates testing and simulation: Contracts allow creating mock services and testing complex scenarios before actual implementation.
- Consistent and accurate documentation: API documentation always reflects the contract and stays up-to-date as services evolve.
- Reduced inter-service errors: In a multi-module system like Horizon, Contract-First ensures transparent and error-free interactions between modules.
One of the tools for testing and documenting APIs of the Horizon project is Hoppscotch, which is a free and open source alternative to Postman. The API test file will be executable with this tool.
Some of API documents are listed as below.