A simple ArchivesSpace plugin to facilitate interaction with the backend via AJAX requests initiated in Javascript. Requests are passed to a controller that validates permissions and interacts with the backend using the JSONModel::HTTP module, so user credentials and session tokens do not need to be handled in Javascript.
- Copy the 'ajax_utility' directory to the 'plugins' directory in ArchivesSpace
- Add the plugin to the list of plugin to load in `config/config.rb':
AppConfig[:plugins] = ['ajax_utility', (other plugins that will use ajax_utility)]
The plugin provides 2 routes that can be used to GET and POST JSON data.
Just add /api to the beginning of the backend REST endpoint URI. For example:
/repositories/1/resources/123
becomes
/api/repositories/1/resources/123
Additional query parameters can be included in the URI as usual, e.g.:
/api/repositories/1/resources/123?resolve[]=subjects
URIs are formulated the same way as they are for GET. JSON data to be passed to the backed should be included with the key 'json'. Here is a sample implemenation using JQuery.post:
var postData = { title: "This is a new title" }
$.post( "/api/repositories/1/resources/123", { json: postData } );