API Spec to Code or Code to API Spec?
1 min readJan 11, 2024
Few software engineers don’t like writing documentation. Some never did. Many tools have been created to create documentation from code, such as Doxygen, Godoc. It’s probably useful for implementation documentation that explains how a function should be used, e.g. Golang has the built-in document generator. However, for API services, I think the API-first approach should be preferred, for a few reasons:
- It liberally forces us to think of API first — This is very important!
- Once the API is ready, the API consumer and API provider can work concurrently.
- Boilerplate code can be (re-)generated easily, taking away the tedious work from developers.
- The implementation and API doc are in sync, which can be enforced by CI/CD.
I think the barrier to adopt this approach is quite low given the many tools available. If you haven’t tired it, I think you should and it can be a game changer.