I have developed a sudden interest for Codeplex, Microsoft’s open source project hosting web site.
It started last week with a post on Marc Anderson’ blog, about JSON, REST, and his infamous SPServices. In a follow up conversation, Marc pointed me to the related discussion on Codeplex. In less than 48 hours, I registered to Codeplex, posted a dozen comments, began following two existing projects, and started two projects myself.
The discussion on SPServices and JSON led me to take a closer look at the jQuery documentation, and discover several features that came with version 1.5. We’ll see how it goes, but the use of “converters” looks promising and should make Marc’s library even more powerful.
As for the two new projects, I’ll post more information as I progress, for now here is a short description.
SPrest
The purpose of SPrest is to abstract the SharePoint 2010 REST services, the same way Marc abstracted Web Services. I had long been thinking about adapting Marc’s library to REST, so this Codeplex discussion was an opportunity to get started. After a long conversation with Marc, our conclusion was that including REST into the existing SPServices didn’t bring much value, so I chose to branch out and create a dedicated project called SPrest.
To be honest, it is not clear whether such a project has real value. REST is more straightforward than Web Services, as demonstrated for example in this article by Jan Tielens. Well, we’ll see…
SPELL
SPELL stands for SharePoint Progressive Enhancement Lightweight Library (just keep in mind I did all of this in less than 48 hours…). Its purpose it to put together some utility functions I often reuse in my customizations, for example identifying the Web Parts present in a page. I’ll explain what I mean by “progressive enhancement” in a future article (it was the main theme of my presentation at the San Diego SharePoint User Group meeting in March).
Here is what I have so far for the SPrest library (questions and feedback welcome, as usual):
<script type="text/javascript"> (function($){ $.extend({ SPrest:{ listData:function(options){ var CRUDtype={"Create":"POST","Read":"GET","Update":"POST","Delete":"DELETE"}; var CRUDheader={"Create":"PUT","Update":"MERGE","Delete":"DELETE"}; // Note: Default settings can be set globally by using the $.ajaxSetup() function. // Note: simple handling of options for this first draft $.ajax({ type: CRUDtype[options.type], headers:(options.action=="Read")?{}:{'X-HTTP-Method-Override':CRUDheader[options.action]}, // Header for POST operations (Create, Update, Delete) url: options.site+"/_vti_bin/listdata.svc/"+options.listName+"?"+options.query, // Note: escaping is currently missing in the url cache:false, dataType:"json", error:options.error, success:options.success }); } // End ListData } // End SPrest }) // End extend })(jQuery); </script>
An example, return the content of the Site Assets library in the Lab site:
<script type="text/javascript"> $.SPrest.listData ({ site:"/Lab", listName:"SiteAssets", success: function(data, textStatus, jqXHR){ alert(jqXHR.responseText);}, error: function(){ alert("error");} }); </script>
Pingback: Two new projects: SPrest and SPELL | Translogistics
Looking forward to digging into REST and the Client Object Model. Any word on REST working for anonymous users?
As far as I know, no hope on that front…
Pingback: Update list items with listdata.svc « Sharepoint…