Documentation-driven
development for
Python web APIs
• Jose Haro Peralta
• Full stack consultant
• Cofounder of microapis.io
@JoseHaroPeralta
@microapisio
EuroPython 2021
$ whoami
35% discount code: ctweuro21
• I’m Jose
• Independent contractor | London
• Full stack developer
• Microservices and APIs
@JoseHaroPeralta
@microapisio
microapis.io
39% discount code: ctwapi21
One-click API mock servers
@JoseHaroPeralta
@microapisio
Connect with Jose
• Twitter: @JoseHaroPeralta
• GitHub: @abunuwas
• Medium: @joseharoperalta /@python-geek
• LinkedIn: https://www.linkedin.com/in/jose-haro-peralta/
@JoseHaroPeralta
@microapisio
This
presentation
covers
• Complexity of API integrations
• What is documentation-driven development and why
it matters?
• How to you can adopt documentation-driven
development?
• REST API (OpenAPI)
• FastAPI
• Validate server implementation with Dredd and
schemathesis
• Build API clients with mock servers
• Continuous Integration and deployment to Heroku
• API visibitility
• Code for this presentation:
https://github.com/abunuwas/europython-2021
@JoseHaroPeralta
@microapisio
API integrations are tricky
API server
API client
12/12/2020 vs 12-12-2020
Misunderstandings drive API integration
failures
• Misunderstanding about data formats
• "2021-07-29" vs "2021/07/29"
• "$21" vs 21
• true vs "True"
Misunderstandings drive API integration
failures
• Misunderstanding about data types
• "2021" vs 2021
• 202.1 vs 202
Misunderstandings drive API integration
failures
• Misunderstanding about optional fields
vs
Misunderstandings drive API integration
failures
• Misunderstanding about the usability of the endpoints
How API
integrations
fail
Lack of
documentation
Bad documentation
Lack of design stage
What is API documentation?
REST -> OpenAPI
GraphQL -> Schema Definition
Language
gRPC -> Protobuf
What is
documentation-
driven
development?
• Also known as design-first, API-first
or contract-first approach
• Design and produce the API
specification first
• Build your server and your API
client (if you have one) against the
specification
• Use the specification to validate
your implementation
Dredd / schemathesis
datamodel-code-generator
(https://github.com/koxudaxi/datamodel-code-generator)
Run Dredd tests with hooks
Run schemathesis tests with stateful links
Running a mock server with prism
Calling a mock server with prism
Running a mock server with microapis.io
Calling a mock server with microapis.io
Configuration for the Travis file
Thanks for listening!
Twitter: @JoseHaroPeralta
GitHub: @abunuwas
Medium: @joseharoperalta /@python-geek
LinkedIn: https://www.linkedin.com/in/jose-haro-peralta/
35% discount code: ctweuro21

Documentation-driven development for Python web APIs