Simon Willison’s Weblog

Subscribe

Why doesn’t the Django framework come with its own REST API out of the box?

20th September 2012

My answer to Why doesn’t the Django framework come with its own REST API out of the box? on Quora

I’d argue that it does. If you want to build a REST API you need to be able to map incoming HTTP requests to handler functions based on their URL, run some custom code and return an HTTP response containing JSON (or maybe XML). Django makes all of this really simple.

Once you go beyond that basic set of functionality things get opinionated very quickly. There are some excellent libraries for Django that help you put together a RESTful oAuth-protected API quickly (https://github.com/toastdriven/d... for example)—but they have pretty strong opinions on how those APIs should be structured. That’s fine for a third party module, but it’s not necessarily the right thing to happen in the core framework.

Guido van Rossum once said of the Python Standard Library that once a module is added to it it already has one foot in the grave... this is very true: once something is part of Django (or Python) core development becomes MUCH more restricted... there are backwards compatibility guarantees to worry about, and a release cycle that’s much, much slower than for a standalone module.

So for something as opinionated and fast-moving as a REST API toolkit, its much better off as a third party module (like tastypie), free from the restrictions that come with being included in Django itself.

Incidentally, this logic is the main reason Django doesn’t yet ship with a built-in database migrations solution yet.

Another thing... once a solution is chosen to ship with Django, the incentive for other developers to try their own approach is reduced. Sometimes it’s better to let a bunch of solutions blossom and explore the space than to prematurely pick a “winner”.

These are just my opinions (and I’m certainly not an active Django contributor these days), but I expect you’d get a similar answer from Django’s current core developers.

This is Why doesn’t the Django framework come with its own REST API out of the box? by Simon Willison, posted on 20th September 2012.

Next: Why is everyone so obsessed with picking faults with Apple's new maps on the iPhone?

Previous: What is a development framework?