Python – How the website should use its own API

apiapi-designArchitecturedjangopython

Im building small web-service which will provide my users with data through API.
Also, some data will be available right on my website.

The question is about how to use my own API? Should my website make a query to, for example, http://website.com/api/users/?format=json and then render data? Because I can use standard Django ORM features, but this is not corresponding with using of own API.

update:
Imagine that I have a database full of games with release date, game name, game platform etc. And on my own website I will show this games as a list or a grid. Also, this data can be reached through API in JSON format, this data can be updated through API and even deleted. And on my own website I have html forms that allow me to do this actions in a user-friendly way. So how should I access my own API? Via POST request to my API or via django ORM directly to database?

Best Answer

Unless the performance overhead of using the web service is an issue, you should definitely use your public API.

This will help you get a consistent behavior between your application and the consumers. It will also avoid code duplication and the best part - if you break your web service you will most likely be the first one to notice it.

The concept is usually referred to as "dogfooding" and Twitter is one example of an application, that dogfoods it's own API.

Related Topic