adeleinr
adeleinr

Reputation: 665

What is the best way to consume a django-piston REST API from a Django view?

I have started using django-piston for creating APIS but I am having trouble finding documentation on how to consume the API from inside django with python. I have seen examples using javascript.

So far I am using urllib to access the API but I wonder if this is the best approach.

I appreciate your input on this!

Upvotes: 4

Views: 608

Answers (1)

eternicode
eternicode

Reputation: 6935

If this is an internal API -- that is, you/your views and the API have the same access to resources -- why are you consuming the API rather than getting its results normally (through model manipulation, etc)? If you want to avoid code duplication, break out common code into separate functions that can be used by both processes.

If this is an external API -- for example, your site is communicating with BitBucket -- an HTTP client is about the only (sane) way to go about consuming it. Though I personally would choose httplib over urllib.

Upvotes: 1

Related Questions