如何扩展CKAN-API?

2024-04-27 00:58:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我想问我如何通过编写自己的扩展来扩展CKAN的API。我在文件里找不到任何东西。 你能举个简单的例子吗?在


Tags: 文件apickan例子
1条回答
网友
1楼 · 发布于 2024-04-27 00:58:02

在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

它正在安装ckan2.2.1。在

相关问题 更多 >