我想问一下如何通过编写自己的 CKAN 扩展来扩展 CKAN 的 API。我在文档中找不到任何内容。 能举个简单的例子吗?
最佳答案
在 OP 的辩护中,文档似乎确实有点不透明。我一直在研究这个,试图获得一个自定义 API 操作来提供 JSON 新闻提要,并最终想出了这个:
import ckan.plugins as plugins
import ckan.plugins.toolkit as toolkit
# Required so that GET requests work
@toolkit.side_effect_free
def get_news(context,data_dict=None):
# The actual custom API method
return {"hello":"world"}
class CustomAPIPlugin(plugins.SingletonPlugin):
plugins.implements(plugins.interfaces.IActions)
def get_actions(self):
# Registers the custom API method defined above
return {'get_news': get_news}
描述创建身份验证插件的教程在这里:
http://docs.ckan.org/en/latest/extensions/tutorial.html#creating-a-new-extension
我所做的是剽窃,但使用 IActions 而不是 IAuthFunctions:
http://docs.ckan.org/en/latest/extensions/plugin-interfaces.html
它正在安装 CKAN 2.2.1。
关于python - 如何扩展 CKAN API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28043973/