I wanted to have a look at the tooling to make the development of the API fast, conform to the specs, and resilient to code changes.
An API is centered around a contract. A document we settled on with the various users of the API. People are going to rely on this spec, so we should seldom change it in the future. If we do, it’s with versioning, so that we never break the contract.
The API server is the program that is going to be accessed by our users via HTTP and serve the information they expect. It’s entirely up to you what you make this server with, and that’s the beauty of interfacing.
For the purpose of this article, I will use FastAPI. This is a Python library that looks like Flask but leverages type hints to optimize the code.
Our source code is going to be inside petstore/petstore. Let’s create a server.py that’s going to contain all of our server code.
You can copy the specs into your project: http get https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v2.0/yaml/petstore.yaml > spec.yaml.