[Building Sakai] Sakai REST services

Steve Swinsburg steve.swinsburg at gmail.com
Wed Dec 7 01:44:24 PST 2011


Hi Jaco,

Glad you found it useful, credit to Aaron Zeckoski as well though, that was a joint presentation.

You hit the nail on the head, same origin policy.

To get around this you'll need to:

1. Use the file:// protocol as that is not subject to the same origin policy (not practical in many cases).
2. Have the app on the same domain (might be best option depending on your deployment)
3. Use a simple server side proxy to make the requests on your behalf (some overhead, YMMV).

Alternatively, there are the SOAP based services.

cheers,
Steve


On 07/12/2011, at 8:36 PM, Jaco Gillman wrote:

> Hi All
> 
>  
> I would like to make use of the Sakai REST services. I came across an insightful online slide (http://www.slideshare.net/steveswinsburg/soap-and-restful-web-services-in-sakai) that explains the REST usage in Sakai, but I still have some questions. When I browse to the link "http://sakai.server/direct/announcement/describe" I can see the announcement decription page on our Sakai deployment. I also see announcement results when I browse to the following links:
> 
> 
> http://sakai.server/direct/announcement/user.json?n=10&d=30
> 
> http://sakai.server/direct/announcement/user.json
> 
>  
> Now, when I try to invoke this service from a normal html page locally (return the data in json format), I do not get any results back in the response, with no errors/exceptions. Is the cross domain to blame here?
> 
>  
> AJAX approach to Sakai REST services implementation:
> 
>  
>                  var url = "http://sakai.server/direct/announcement/user.json";
> 
>                 //var url = "http://sakai.server/direct/announcement/user.json?n=10&d=30";
> 
>                   setSakaiOLEConfiguration();
> 
>                   new Ajax.Request(url, {
> 
>                                   method: 'get', 
> 
>                                   onSuccess: function(transport) {
> 
>                                                 var response = transport.responseJSON || "no response text";
> 
>                                                 alert("testSakaiWS: " + response);                                          
> 
>                                   },
> 
>                                   onException : function(error) {
> 
>                                                 alert('exception');
> 
>                                   },
> 
>                                   onFailure : function() {
> 
>                                                 alert('failure');
> 
>                                   }
> 
>                 });
> 
>  
>  
> Prototype.js lib approach to Sakai REST services implementation:
> 
>  
>     var url = "http://sakai.server/direct/announcement/user.json";
> 
>     //var url = "http://sakai.server/direct/announcement/user.json?n=10&d=30";
> 
>     xmlhttp.open('GET',url,true);
> 
>     xmlhttp.send(null);
> 
>     xmlhttp.onreadystatechange = function() {
> 
>          if (xmlhttp.readyState == 4) {
> 
>              if ( xmlhttp.status == 200) {
> 
>                  alert(xmlhttp.responseJSON);
> 
>                 //alert(xmlhttp.responseText);
> 
>             }
> 
>             else
> 
>                  alert("Error ->" + xmlhttp.responseText);
> 
>         }
> 
>      };
> 
>  
> Neither one of these approaches (and neither URL values in both examples), return any values whatsoever.
> 
> 
> 
> 
> 
> 
> Regards,
> 
> 
> Jaco Gillman
> Java Developer
> opencollab
> Tel: +27 21 970 4017  |  Fax: +27 21 914 3098
> Email: jaco at opencollab.co.za  |  Skype: gillmanjc
> Web: www.opencollab.co.za
> 
> 
> 
> 
> 
> 
> _______________________________________________
> sakai-dev mailing list
> sakai-dev at collab.sakaiproject.org
> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
> 
> TO UNSUBSCRIBE: send email to sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of "unsubscribe"

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20111207/64aa27ed/attachment.html 


More information about the sakai-dev mailing list