The preparation for my talk on Monday at the Wharton Web Conference got me thinking a lot about the impedance mismatch between web frameworks and REST APIs. The more you develop REST APIs with frameworks like Django or Flask, the more clear it is that something is amiss. It's a subtle feeling of needing to fight against the grain to accomplish your goal.
Which of course led me down another rabbit hole: server-side web frameworks in general. There are two things they pretty much suck at right now: helping you write REST APIs and supporting bidirectional communication over things like WebSockets.
I wondered what would happen if you took the guts of Flask (i.e. Werkzeug) and built around it a framework of frameworks. A way to write a real-time application or a REST API or a series of simple templated pages or an entirely static site or a ... well, you get the idea. I wondered, and then I started writing.
My current progress is (as of ten minutes ago) called "Omega". It's a fully functional framework in some regards, and a totally incomplete one in others. Here, though, is what it would look like to have an automatically generated, browsable REST API with real-time chat (bet you didn't see that coming).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
And here are the models.py
and sockets.py
files:
(models.py
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
(sockets.py
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
Pretty minimal. I've become obsessed with the notion of auto-generating as much as humanly possible so that the code required by the client is literally the minimal amount of information that needs to be transmitted to describe how their system should look. That means that Omega gives you Django admin-style functionality out of the box, as well as django-rest-framework functionality on the API side. Customization is possible, but the goal is to avoid it unless absolutely necessary. It's taking the idea of an opinionated framework to the extreme, all the way to look and feel (both of which are purposely hideous, at the moment.
The thing is, though, you can copy that code, run it, use curl
to interact
with the REST API, browse through it and edit stuff by hitting
localhost:5000/
, and even connect two browser tabs to localhost:5000/
and
hold a chat session between them. You can do all of that right now, in a way
that asks as little of you as possible.
The Future
Omega is not done; I mean, it's barely usable. It will likely never be "done". Instead, it's an experiment in taking a different tack than today's "micro-frameworks". You might call it the first "macro-framework". Or you might call it "Omega: The Last Framework". Either way, I'm guessing you've not seen anything quite like it before.
Posted on by Jeff Knupp