17 January 2019

Django REST Framework Abstraction Grid

Django REST Framework

The Django Rest Framework (DRF) is the leading REST API library for Django projects. It has fantastic and comprehensive documentation, much like the Django project. However, with all the classes, mixins, and other options it provides, the abstractions can get a bit confusing.

Whenever I use a library I like to have a clear picture of its main concepts and how the pieces fit together, so I ended up plotting this out for the DRF to show how the URLs, REST operations, and CRUD layer all fit together to make an API. This is intended for someone who has read over the DRF documentation and feels like they kind of get it, but starts to feel lost in all the different layers of abstraction.

Behold, the Django REST Framework - Abstraction Grid:

Django REST Framework Abstraction Grid

(click to view full size: svg | pdf | png)

The big things to see here are:

  1. You are expected to follow their mostly flat structure of "/{your_objects}" or "/{your_objects}/{pk}" and to apply the various HTTP methods as shown—if you fight this structure, you will have a bad time
  2. The Generics are all doing the REST operation work (connecting to a URL and HTTP method)
  3. The Mixins are all doing the CRUD operations (connecting into the DB with your model)
  4. See if you can use GenericViews Combos or better the ViewSets
  5. This doesn’t include serializers, sorry!

If some of this is outdated, let me know! I have it in a sketch file that is easy to update.


Did you find this helpful or fun? Please donate!

donate via btc or eth

btc: 18jCzwsZDGQYcs6Kyv92pd4683cnnxm1Dd
eth: 0xC285F21Cb271Cb4B3F70c4C47B2f7B26063AF590
paypal: paypal.me/mrcoles
comments powered by Disqus

Peter Coles

Peter Coles

is a software engineer who lives in NYC, is currently working on this, and blogging here. more »

github · soundcloud · @lethys · rss

It’s time to get big money out of politics. Join the kick-started campaign to put government back in the hands of the people. Pledge mayday.us now