用Django使用RESTful API [英] Consuming a RESTful API with Django

查看:80
本文介绍了用Django使用RESTful API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个需要与第三方RESTful API进行交互的Django应用程序,为该资源制作各种GET,PUT等。我正在寻找的是在Django中表示该API的好方法。

I'm building a Django application that needs to interact with a 3rd party RESTful API, making various GETs, PUTs, etc to that resource. What I'm looking for is a good way to represent that API within Django.

最明显但可能不太优雅的解决方案似乎是创建一个具有映射到Web服务查询的各种方法的模型。另一方面,似乎使用类似自定义DB后端的东西可以提供更多的灵活性,更好地集成到Django的ORM中。

The most obvious, but perhaps less elegant solution seems to be creating a model that has various methods mapping to webservice queries. On the other hand, it seems that using something like a custom DB backend would provide more flexibility and be better integrated into Django's ORM.

注意事项:这是Django第一个真正的项目,所以可能我在这里缺少一些明显的东西。

推荐答案

请求 库可以轻松编写一个REST API消费者。还有一个名为 slumber 的Python库,它基于请求的顶部,用于消除REST API的明确目的。这将有助于您的工作有赖于API真正的RESTful。

The requests library makes it easy to write a REST API consumer. There is also a Python library called slumber, which is built on top of requests, for the explicit purpose of consuming REST APIs. How well that will work for you likely depends on how RESTful the API really is.

这篇关于用Django使用RESTful API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆