How can I extend the CKAN API?

I would like to ask how can I extend the CKAN API by writing my own extension for CKAN. I could not find anything in the documentation. Could you give a simple example?

+4
source share
1 answer

In the defense of OP, the documentation looks a bit opaque. I considered this while trying to get a custom API action to feed news into JSON, and finally came up with the following:

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}

A tutorial describing creating an authentication plugin is here:

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

I did this to plagiarize, but using IActions, not IAuthFunctions:

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

Works on installing CKAN 2.2.1.

+8
source

All Articles