I would like to ask how can I extend CKAN's API by writing my own extension for CKAN. I could not find anything in the documentation. Could you give some simple example please?
For CKAN purposes, data is published in units called “datasets”. A dataset is a parcel of data - for example, it could be the crime statistics for a region, the spending figures for a government department, or temperature readings from various weather stations.
In the OP's defence, the documentation does seem to be a bit opaque. 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:
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
What I've done is to plagiarise that, but using IActions rather than IAuthFunctions:
http://docs.ckan.org/en/latest/extensions/plugin-interfaces.html
It's working on an installation of CKAN 2.2.1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With