Using the API with Javascript
From CKAN
Using CKAN (via its API) from javascript including how to use the official CKAN javascript client library.
Contents |
Pre-requisities
3 Learn jquery in 18 minutes: http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery
Getting Started
Try out the online demo
Visit: http://okfnlabs.org/ckanjs/app and play around
Get the code on your machine
- https://github.com/okfn/ckanjs
- Select download and save on disk
- Uncompress
- Open app/index.html - should look like the app you saw in previous step
Start Changing Things
Get your own file
- Copy and paste the index.html to myindex.html
- Look in myindex.html and replace contents of
jQuery(document).ready(function($) {
...
}
so it reads
jQuery(document).ready(function($) {
cfg = {
endpoint: 'http://ckan.net'
}
CKAN.Model.configure(cfg);
});
Search for a dataset
- Use this as an example package: http://thedatahub.org/api/rest/package/ckan
CKAN.Model.search('ckan', function(data) {
$('.flash-banner-box').html(data);
});
In your console (firebug or chrome) you should see an object.