Working on a small project of mine I tried to catch up with web user interface ‘state of the art’, as per my understanding it looks like this:
- On servers side splits to static and dynamic content:
- static content is served via proven web servers like apache, ngix – on global scale this task might be delegated to CDN providers.
- dynamic content is available via Web Services API – now most common is RESTful API with JSON as data serialization format (with XML often as an alternative, but more complicated technologies like SOAP/WSDL seem to be disappearing) .
Following diagram summarizes idea of single page application:
I wanted to try this new paradigm with Django framework, which is more oriented to classic multi-page web applications, but has so many good features, that I hoped it can serve me well also in this case.
First I needed to provide RESTful API – simple approach would be to use Django views to return JSON, but for more complex approach some framework would be useful – luckily there are several RESTful frameworks for Django – these two seems to be most prominent: django-rest-framework and django-tastypie
I’ve chosen django-rest-framework, it’s very well documented and based on well-know Django technologies – forms and views – resources here are defined as a combination of serializers (which are defined in a way similar to Django forms) and views (which bind serialized data to HTTP methods). Django-rest-framework understands Django models so it is easy to create an API from existing models. Django-rest-framework also provides nice way to access API from web browser, so you can test it and play with it.