{# Displays information about accessing a resource via the API. resource_id - The resource id embedded - If true will not include the "modal" classes on the snippet. Example {% snippet 'ajax_snippets/api_info.html', resource_id=resource_id, embedded=true %} #} {% set resource_id = h.sanitize_id(resource_id) %} {% set sql_example_url = h.url_for(controller='api', action='action', ver=3, logic_function='datastore_search_sql', qualified=True) + '?sql=SELECT * from "' + resource_id + '" WHERE title LIKE \'jones\'' %} {# not urlencoding the sql because its clearer #}
{{ _('Access resource data via a web API with powerful query support') }}. {% trans %} Further information in the main CKAN Data API and DataStore documentation.
{% endtrans %}{{ _('The Data API can be accessed via the following actions of the CKAN action API.') }}
| {{ _('Create') }} | {{ h.url_for(controller='api', action='action', ver=3, logic_function='datastore_create', qualified=True) }} |
|---|---|
| {{ _('Update / Insert') }} | {{ h.url_for(controller='api', action='action', ver=3, logic_function='datastore_upsert', qualified=True) }} |
| {{ _('Query') }} | {{ h.url_for(controller='api', action='action', ver=3, logic_function='datastore_search', qualified=True) }} |
| {{ _('Query (via SQL)') }} | {{ h.url_for(controller='api', action='action', ver=3, logic_function='datastore_search_sql', qualified=True) }} |
{{ h.url_for(controller='api', action='action', ver=3, logic_function='datastore_search', resource_id=resource_id, limit=5, qualified=True) }}
{{ h.url_for(controller='api', action='action', ver=3, logic_function='datastore_search', resource_id=resource_id, q='jones', qualified=True) }}
{{sql_example_url}}
{{ _('A simple ajax (JSONP) request to the data API using jQuery.') }}
var data = {
resource_id: '{{resource_id}}', // the resource id
limit: 5, // get 5 results
q: 'jones' // query for 'jones'
};
$.ajax({
url: '{{ h.url_for(controller='api', action='action', ver=3, logic_function='datastore_search', qualified=True) }}',
data: data,
dataType: 'jsonp',
success: function(data) {
alert('Total results found: ' + data.result.total)
}
});
import urllib
url = '{{ h.url_for(qualified=True, controller='api', action='action', ver=3, logic_function='datastore_search', resource_id=resource_id, limit=5) + '&q=title:jones' }}' {# not urlencoding the ":" because its clearer #}
fileobj = urllib.urlopen(url)
print fileobj.read()