I’m looking for some advice on “best practice” when writing a web app that exposes data via an API as well as human-readable pages. The question is platform-neutral, but I’m looking at this from the perspective of a Django site.
I’ve been watching the “30 Days to Learn jQuery” tutorials at tutsplus.com, and just saw the video where they retrieve JSON data from the Twitter API and render it on the page. Now, currently, I would build views that access the Django models and pass some data to the template, which is rendered for the user. However, this got me thinking — if I’ve already got a JSON API using tastypie, why not write Javascript in my template to read the data from there?
So, can anyone tell me why I should or should not take this approach?
There is going to be some sort of performance overhead. If each request requires you to consume an API that you are the owner of, there are things like authentication that become unnecessary. In some cases it is an unnecessary layer of abstraction.
Additionally, I think that it is easier/cleaner to develop templates based around django objects than having to consume the Javascript and manipulate it via jquery.