【发布时间】:2018-12-06 01:49:10
【问题描述】:
我为我的 python 代码编写了一个 API,如下所示:
def greet_in_python(name, greets="Hello"):
## in real life this implementation may be more complex and has other **python** dependencies
....
return greets + " " + name
但是只有python开发者可以使用我的api。
我想要做的是同样的事情,但使用不同的语言,如 javascript,并且无需从 python 重写整个代码。 我认为javascript必须有一种方法可以与这个python api进行通信,执行它并获得结果,以便javascript开发人员也可以使用我的api。
greet_in_javascript(name, greets) {
// talk to my python api
// return the result easily
}
在一般意义上,两种语言如何相互交谈?
【问题讨论】:
-
有很多方法,但现在最流行的选择是使用 REST API。有关基于 Python 的解决方案,请参阅 django-rest-framework.org。
标签: javascript python api communication-protocol