API-First Design
and Django
The tale of caring for your fellow developer
Olá! 🇧🇷
I am Klaus Laube
In ❤ with Django since version 0.96
Back-end developer at Son of a Tailor
klauslaube.com.br
github.com/kplaube
What’s an API again?
“(...) a set of dedicated URLs that return pure
data responses — meaning the responses
won’t contain the kind of presentational
overhead that you would expect in a
graphical user interface like a website.
Petr Gazarov
https://www.freecodecamp.org/news/what-is-an-api-in-english-please-b880a3214a82/
Let's build a
product! 🚀
The Code-First approach
Install Django
It’s not up to decision
picking a different
framework ❤
The Code-First approach
Install Django
It’s not up to decision
picking a different
framework ❤
Design the
database
Come up with
diagrams, define the
indexes, describe
relationships 💾
The Code-First approach
Install Django
It’s not up to decision
picking a different
framework ❤
Design the
database
Come up with
diagrams, define the
indexes, describe
relationships 💾
Write the code
Organize the packages,
do some TDD, write the
models, the views,
perhaps some API 👨‍💻
The Code-First approach
Install Django
It’s not up to decision
picking a different
framework ❤
Design the
database
Come up with
diagrams, define the
indexes, describe
relationships 💾
Write the code
Organize the packages,
do some TDD, write the
models, the views,
perhaps some API 👨‍💻
Deploy &
release
Deal with CI, CD, PaaS,
provisioning,
monitoring, caching,
etc 🖥
The Code-First approach
Install Django
It’s not up to decision
picking a different
framework ❤
Design the
database
Come up with
diagrams, define the
indexes, describe
relationships 💾
Write the code
Organize the packages,
do some TDD, write the
models, the views,
perhaps some API 👨‍💻
Expose
Let other stakeholders
know about your
release 🎉
☝
Here is where we’ll
start to integrate with
other developers
Deploy &
release
Deal with CI, CD, PaaS,
provisioning,
monitoring, caching,
etc 🖥
“Today Django is arguably used more often as
just a back-end API rather than a full
monolithic website solution at large
companies!
William S. Vincent
Django for APIs
What’s API-First?
“(...) the first, most waterfall aspect of
application development is the design of the
API’s.
Casey Lutz
https://medium.com/trimble-maps-engineering-blog/api-first-development-and-openapi-83
5afb46b7f1
3 principles of
API-First Design
#1
Your API is the first user interface of your application
#2
Your API comes first, then the implementation
#3
Your API is described (and maybe even self-descriptive)
It’s about caring for other
developers! 👨‍💻 👩‍💻
How can we do
that with
Django? 🤔
Design the API
Understand the
requirements, know your
stakeholders, set standards,
start defining behaviours.
API Blueprint example 👉
20
Validate
Get stakeholders involved,
think about use cases,
validate ideas through mock
servers, and get an
agreement.
Or you can use Prism:
https://stoplight.io/open-source/pris
m/
21
Test! Test! Test!
https://dredd.org
Implement
It’s time for some coding.
And it’s not just you! With a
solid contract your
stakeholders can start the
development as well.
Django REST Framework example 👉
23
What about {over,under}-fetching?
https://github.com/rsinger86/drf-flex-fields
Or consider
GraphQL 🤷‍♂
It’s official!
It’s time to turn the
agreement into a
specification.
rest_framework (with
uritemplate and pyyaml) is
enough to do this job.
26
$ python manage.py generateschema >
openapi-schema.yml
How to deal with changes?
▷ Path: mytodoapp.com/v1/tasks
▷ Querystring: mytodoapp.com/tasks?version=1.0
▷ Host: v1.mytodoapp.com/tasks
▷ Accept header: Accept: application/json; version=1.0
▷ Custom header: X-API-VERSION
▷ No versioning at all 🙃
https://www.django-rest-framework.org/api-guide/versioning/
Release
Turn the specification public.
Publish the API
documentation. drf-yasg is
your sidekick here.
Engage
Promote your API, start
monitoring, collect feedback,
and learn from your mistakes
and successes.
29
Repeat ♻
Further readings:
API-First Processes
and Tools
bit.ly/api-first-article
31
Further readings:
How To Design
Great APIs With
API-First Design
bit.ly/3hQYw7d
32
Further readings:
Django for APIs
leanpub.com/djangoforapis
33
Tak! 🇩🇰
You can find me at:
klauslaube.com.br
github.com/kplaube
Django Forum: kplaube

API-First Design and Django

  • 1.
    API-First Design and Django Thetale of caring for your fellow developer
  • 2.
    Olá! 🇧🇷 I amKlaus Laube In ❤ with Django since version 0.96 Back-end developer at Son of a Tailor klauslaube.com.br github.com/kplaube
  • 3.
  • 4.
    “(...) a setof dedicated URLs that return pure data responses — meaning the responses won’t contain the kind of presentational overhead that you would expect in a graphical user interface like a website. Petr Gazarov https://www.freecodecamp.org/news/what-is-an-api-in-english-please-b880a3214a82/
  • 5.
  • 6.
    The Code-First approach InstallDjango It’s not up to decision picking a different framework ❤
  • 7.
    The Code-First approach InstallDjango It’s not up to decision picking a different framework ❤ Design the database Come up with diagrams, define the indexes, describe relationships 💾
  • 8.
    The Code-First approach InstallDjango It’s not up to decision picking a different framework ❤ Design the database Come up with diagrams, define the indexes, describe relationships 💾 Write the code Organize the packages, do some TDD, write the models, the views, perhaps some API 👨‍💻
  • 9.
    The Code-First approach InstallDjango It’s not up to decision picking a different framework ❤ Design the database Come up with diagrams, define the indexes, describe relationships 💾 Write the code Organize the packages, do some TDD, write the models, the views, perhaps some API 👨‍💻 Deploy & release Deal with CI, CD, PaaS, provisioning, monitoring, caching, etc 🖥
  • 10.
    The Code-First approach InstallDjango It’s not up to decision picking a different framework ❤ Design the database Come up with diagrams, define the indexes, describe relationships 💾 Write the code Organize the packages, do some TDD, write the models, the views, perhaps some API 👨‍💻 Expose Let other stakeholders know about your release 🎉 ☝ Here is where we’ll start to integrate with other developers Deploy & release Deal with CI, CD, PaaS, provisioning, monitoring, caching, etc 🖥
  • 11.
    “Today Django isarguably used more often as just a back-end API rather than a full monolithic website solution at large companies! William S. Vincent Django for APIs
  • 12.
  • 13.
    “(...) the first,most waterfall aspect of application development is the design of the API’s. Casey Lutz https://medium.com/trimble-maps-engineering-blog/api-first-development-and-openapi-83 5afb46b7f1
  • 14.
  • 15.
    #1 Your API isthe first user interface of your application
  • 16.
    #2 Your API comesfirst, then the implementation
  • 17.
    #3 Your API isdescribed (and maybe even self-descriptive)
  • 18.
    It’s about caringfor other developers! 👨‍💻 👩‍💻
  • 19.
    How can wedo that with Django? 🤔
  • 20.
    Design the API Understandthe requirements, know your stakeholders, set standards, start defining behaviours. API Blueprint example 👉 20
  • 21.
    Validate Get stakeholders involved, thinkabout use cases, validate ideas through mock servers, and get an agreement. Or you can use Prism: https://stoplight.io/open-source/pris m/ 21
  • 22.
  • 23.
    Implement It’s time forsome coding. And it’s not just you! With a solid contract your stakeholders can start the development as well. Django REST Framework example 👉 23
  • 24.
  • 25.
  • 26.
    It’s official! It’s timeto turn the agreement into a specification. rest_framework (with uritemplate and pyyaml) is enough to do this job. 26 $ python manage.py generateschema > openapi-schema.yml
  • 27.
    How to dealwith changes? ▷ Path: mytodoapp.com/v1/tasks ▷ Querystring: mytodoapp.com/tasks?version=1.0 ▷ Host: v1.mytodoapp.com/tasks ▷ Accept header: Accept: application/json; version=1.0 ▷ Custom header: X-API-VERSION ▷ No versioning at all 🙃 https://www.django-rest-framework.org/api-guide/versioning/
  • 28.
    Release Turn the specificationpublic. Publish the API documentation. drf-yasg is your sidekick here.
  • 29.
    Engage Promote your API,start monitoring, collect feedback, and learn from your mistakes and successes. 29
  • 30.
  • 31.
    Further readings: API-First Processes andTools bit.ly/api-first-article 31
  • 32.
    Further readings: How ToDesign Great APIs With API-First Design bit.ly/3hQYw7d 32
  • 33.
    Further readings: Django forAPIs leanpub.com/djangoforapis 33
  • 34.
    Tak! 🇩🇰 You canfind me at: klauslaube.com.br github.com/kplaube Django Forum: kplaube