[英]How can I extend CKAN API?
我想問一下如何通過為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。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.