= REST Interface = Resources are accessible via [wiki:S3XRC/RESTfulAPI/URLFormat RESTful URIs] to allow the creation of Mash-ups: JSON uploads should be PUT to http://server.domain/eden/module/resource.json NB JSON must not include trailing commas in lists (just like Internet Explorer). [This is a SimpleJSON limitation] == Testing == === RESTclient === * http://code.google.com/p/rest-client/ Use pre-emptive authentication, when you need to login. === AJAX === Authenticate using: {{{ function make_base_auth(user, password) { var tok = user + ':' + pass; var hash = Base64.encode(tok); return 'Basic ' + hash; } var auth = make_basic_auth('username@example.com', 'password'); var url = 'http://host.domain/eden/controller/function?vars'; // RAW request = new XMLHttpRequest(); request.setRequestHeader('Authorization', auth); request.open('PUT', url, true); // async=true request.send(bodyContent); // ExtJS Ext.Ajax.request({ url : url, method : 'GET', headers : { Authorization : auth } }); // jQuery $.ajax({ url : url, method : 'GET', beforeSend : function(req) { req.setRequestHeader('Authorization', auth); } }); }}} Thanks to: * http://coderseye.com/2007/how-to-do-http-basic-auth-in-ajax.html === CURL === For testing/PUT using CURL follow the example In the example - name%40example.com represents your login name@example.com and password is to be replaced by your password. person.xml is the file name to PUT {{{ curl -H 'content-type:application/xml' -T person.xml http://name%40example.com:password@localhost:8000/sahana/pr/person.xml&ignore_errors=False }}} === WGET === Use the --auth-no-challenge option in order to login to Eden. == !WordPress integration == Courtesy of timClicks. This example is for !HumanityRoad's !WordPress to pull in Hospitals data from Sahana Eden: {{{
%s
%s
'.implode($a).'
'; }; // untested function check_and_set($item, $assoc_array) { if (array_key_exists($item, $assoc_array)) { $val = $assoc_array[$item]; } else { $val = ' '; }; return $val; }; function process_hospital_info($hospital) { global $hospital_table_format; $city = check_and_set('city', $hospital); $website = check_and_set('website', $hospital); $name = check_and_set('name', $hospital); $address = check_and_set('address', $hospital); $phone = check_and_set('phone', $hospital); $email = check_and_set('email', $hospital); $lat = check_and_set('@lat', $hospital['$k_location_id']); $lon = check_and_set('@lon', $hospital['$k_location_id']); $comments = check_and_set('comments', $hospital); $modified_by = check_and_set('@modified_by', $hospital); $last_modified = check_and_set('@modified_on', $hospital); $uuid = check_and_set('@uuid', $hospital); return sprintf($hospital_table_format, $website, $name, $address, $city, $phone, $website, $email, $lat, $lon, $comments, $modified_by, $last_modified, $uuid); }; echo $head; echo '