Just a thought…

Harmonica neck holders but iphones

Django REST Framework

The Dango 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.

Examples of how to use await at the top-level in the Node repl and JavaScript web console. read full post…
An example of how to safely inline JSON within a script in a Jekyll template to avoid XSS attacks and to allow access to that data in your own JavaScript. read full post…
A very short example of how to pass a function into setState in React. read full post…

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