简体   繁体   English

如何扩展CKAN API?

[英]How can I extend CKAN API?

I would like to ask how can I extend CKAN's API by writing my own extension for CKAN. 我想问一下如何通过为CKAN编写自己的扩展来扩展CKAN的API。 I could not find anything in the documentation. 我在文档中找不到任何内容。 Could you give some simple example please? 你能举个简单的例子吗?

In the OP's defence, the documentation does seem to be a bit opaque. 在OP的辩护中,文档看起来确实有点不透明。 I've been looking at this in an attempt to get a custom API action for supplying JSON news feed to work, and finally came up with this: 我一直在寻找这个,试图获得一个自定义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}

The tutorial which describes creating an authentication plugin is here: 描述创建身份验证插件的教程如下:

http://docs.ckan.org/en/latest/extensions/tutorial.html#creating-a-new-extension http://docs.ckan.org/en/latest/extensions/tutorial.html#creating-a-new-extension

What I've done is to plagiarise that, but using IActions rather than IAuthFunctions: 我所做的是抄袭,但使用IActions而不是IAuthFunctions:

http://docs.ckan.org/en/latest/extensions/plugin-interfaces.html http://docs.ckan.org/en/latest/extensions/plugin-interfaces.html

It's working on an installation of CKAN 2.2.1. 它正在安装CKAN 2.2.1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM