Let me share a story with you about two developers working at a Malt, Europe's leading freelance management system & marketplace.
Dev-1: Hi there! We have an issue on production. It seems that a request was sent where “company id” is not given. Dev-2: Oops! But I thought we agreed on an anonymous mode? Dev-1: That’s actually a great idea. You mean that company id is not required? Dev-2: Exactly! Dev-1: Thanks! I will update the data model and push the changes!
As the conversation above suggests, sending data between two applications can easily fail if the requirements are not defined up front. Even for simple requests a lot of decisions have to be made: are the fields optional or mandatory? What about the returned payloads and their data types? Do we need default values? If we are not clear what we will expect (from the request) and what we will return (in the response), in the worst case, the request will fail and we spend time debugging, like above.
To overcome this issue, we decided to move to a contract-first approach, where we define the exact request and response and generate the endpoints and data models from there using the OpenAPI generator. The OpenAPI generator is a powerful tool that allows you to automatically generate API client libraries, server stubs, documentation, and configuration from an OpenAPI specification, or a “contract” between two applications. This contract forms the basis for generating the endpoint stubs for our python applications but also for the client models and code. Starting with the contract can significantly speed up the development process and improve the consistency of your API implementations.
During this talk we will address the following topics: