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 @JoseHaroPeralta @microapisio Repository for this presentation: https://github.com/abunuwas/europython-2021
API integrations are tricky API server API client
Major causes of API integration failures • Backend-driven API development • Lack of separation between API layer and the rest of the app • Misunderstandings about the API • Lack of validation
Fundamental law of API integrations No API survives first contact with its client
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)
• GitHub: https://github.com/apiaryio/dredd Generate tests with Dredd
Run Dredd tests with hooks
Running tests with Dredd
Validating the API server implementation with schemathesis • GitHub: https://github.com/schemathesis/schemathesis
Run schemathesis tests with stateful links
Run schemathesis tests with stateful links
Building API clients against mock servers We use a mock API server to build the client
Run a local server with Prism • Stoplight’s Prism library • GitHub: https://github.com/stoplightio/prism
Running a mock server with prism
Running a mock server in the cloud • Stoplight • Postman • MockLab • microapis.io
Running a mock server in the cloud
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
Links • Microservice APIs in Python by J Haro (mng.bz/nz48) • Building and deploying reliable APIs with FastAPI by J Haro (https://www.twitch.tv/videos/1088283640) • Documentation-driven development for APIs by J Haro (https://link.medium.com/m2A3rOxUfib) • Developing API clients doesn’t need to be a pain by J Haro (https://link.medium.com/0B9vt7DUfib) • Design patterns for modern web APIs by D Luecke (https://blog.feathersjs.com/design-patterns-for-modern-web-apis-1f046635215) • The design of web APIs by A Lauret (https://www.manning.com/books/the- design-of-web-apis) • API Design Patterns by JJ Geewax (https://www.manning.com/books/api-design- patterns)

Documentation-driven development for Python web APIs v2

  • 1.
    Documentation-driven development for Python webAPIs • Jose Haro Peralta • Full stack consultant • Cofounder of microapis.io @JoseHaroPeralta @microapisio EuroPython 2021
  • 2.
    $ whoami 35% discountcode: ctweuro21 • I’m Jose • Independent contractor | London • Full stack developer • Microservices and APIs @JoseHaroPeralta @microapisio
  • 3.
    microapis.io 39% discount code:ctwapi21 One-click API mock servers @JoseHaroPeralta @microapisio
  • 4.
    Connect with Jose •Twitter: @JoseHaroPeralta • GitHub: @abunuwas • Medium: @joseharoperalta /@python-geek • LinkedIn: https://www.linkedin.com/in/jose-haro-peralta/ @JoseHaroPeralta @microapisio
  • 5.
    This presentation covers • Complexity ofAPI 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 @JoseHaroPeralta @microapisio Repository for this presentation: https://github.com/abunuwas/europython-2021
  • 6.
    API integrations aretricky API server API client
  • 7.
    Major causes ofAPI integration failures • Backend-driven API development • Lack of separation between API layer and the rest of the app • Misunderstandings about the API • Lack of validation
  • 8.
    Fundamental law of API integrations NoAPI survives first contact with its client
  • 9.
    What is APIdocumentation? REST -> OpenAPI GraphQL -> Schema Definition Language gRPC -> Protobuf
  • 10.
    What is documentation- driven development? • Alsoknown 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
  • 12.
  • 14.
  • 16.
  • 17.
    Run Dredd testswith hooks
  • 18.
  • 19.
    Validating the APIserver implementation with schemathesis • GitHub: https://github.com/schemathesis/schemathesis
  • 20.
    Run schemathesis testswith stateful links
  • 21.
    Run schemathesis testswith stateful links
  • 22.
    Building API clientsagainst mock servers We use a mock API server to build the client
  • 23.
    Run a localserver with Prism • Stoplight’s Prism library • GitHub: https://github.com/stoplightio/prism
  • 24.
    Running a mockserver with prism
  • 26.
    Running a mockserver in the cloud • Stoplight • Postman • MockLab • microapis.io
  • 27.
    Running a mockserver in the cloud
  • 28.
    Running a mockserver with microapis.io
  • 29.
    Calling a mockserver with microapis.io
  • 30.
  • 31.
    Thanks for listening! Twitter:@JoseHaroPeralta GitHub: @abunuwas Medium: @joseharoperalta /@python-geek LinkedIn: https://www.linkedin.com/in/jose-haro-peralta/ 35% discount code: ctweuro21
  • 32.
    Links • Microservice APIsin Python by J Haro (mng.bz/nz48) • Building and deploying reliable APIs with FastAPI by J Haro (https://www.twitch.tv/videos/1088283640) • Documentation-driven development for APIs by J Haro (https://link.medium.com/m2A3rOxUfib) • Developing API clients doesn’t need to be a pain by J Haro (https://link.medium.com/0B9vt7DUfib) • Design patterns for modern web APIs by D Luecke (https://blog.feathersjs.com/design-patterns-for-modern-web-apis-1f046635215) • The design of web APIs by A Lauret (https://www.manning.com/books/the- design-of-web-apis) • API Design Patterns by JJ Geewax (https://www.manning.com/books/api-design- patterns)