开发者

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

开发者 https://www.devze.com 2023-01-19 21:42 出处:网络
I have started using django-piston for creating APIS but I am ha开发者_运维知识库ving trouble finding documentation on how to consume the API from inside django with python. I have seen examples using

I have started using django-piston for creating APIS but I am ha开发者_运维知识库ving 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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消