SharePoint 2010 REST-like Services – Getting them to work!

Given that it is only beta, I still have to give SharePoint 2010 some leaway yet, until RTM comes out, who knows if
these things will be the same or not. 

Anyone that has programmed Facebook API, knows they have one of the most intense and best documented REST-ful
service layers on the planet!  I have many applications that use their API and the OpenID login IP-STS.  If you were to
look at Facebook and their implementation, you would know it is the BEST way to implement REST services.  I give them
full credit for the revolution that has started!

Given that, let's look at SharePoint 2010 and its REST-like services.  Here's my issues:

  1. Performance sucks
    1. Implementation should have been with HttpHandler vs "Accept" header in the HTTP request with the requested
      format you want returned.  This adds 23 bytes to every request, oh and wait, it gets better, for some reason you
      need a "if-match" header too, another 15 bytes.  Facebook simply does this in the request URL listdata.atom or
      listdata.xml – wow, how easy is that?
    2. My favorite tweet about this REST Implementation: "Oh my god, they killed REST, you bastards!"
  2. Documentation so far is poor
    1. Take for instance the "POST" for adding a new item, the documentation is wrong, it says to do this:

POST /_vti_bin/ListData.svc/Employees HTTP/1.1
Accept: application/atom+xml
Content-Type: application/atom+xml
Host: www.contoso.com
Content-Length: ###
Expect: 100-continue
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns="http://www.w3.org/2005/Atom">
<category scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" term="Microsoft.SharePoint.Linq.EmployeesItem" />
<title />
<author>
<name />
</author>
<updated>2009-04-30T02:15:21.1353156Z</updated>
<id />
<link href="http://www.contoso.com/_vti_bin/ListData.svc/Projects(2)"
rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Projects"
type="application/atom+xml;type=feed" />
<link href="http://www.contoso.com/_vti_bin/ListData.svc/Projects(3)"
rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Projects"
type="application/atom+xml;type=feed" />
<content type="application/xml">
<m:properties>
<d:Created m:type="Edm.DateTime" m:null="true" />
<d:FullName>James Earl Jones</d:FullName>
<d:HireDate m:type="Edm.DateTime">1987-04-29T19:15:14.7861156-07:00</d:HireDate>
<d:ID m:type="Edm.Int32">0</d:ID>
<d:Modified m:type="Edm.DateTime" m:null="true" />
<d:Path m:null="true" />
<d:Salary m:type="Edm.Double">195000</d:Salary>
<d:Version m:null="true" />
<d:Owshiddenversion m:type="Edm.Int32" m:null="true" />
</m:properties>
</content>
</entry>

The error is in the "category" element, you are not using "Linq", you should be using "DataService".

Changing the term attribute will fix your issues:

<category scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"
term="Microsoft.SharePoint.Linq.EmployeesItem" />

TO:

<category scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"
term="Microsoft.SharePoint.DataService.EmployeesItem" />

You should also wrap your WebRequest calls in an try/catch handling a WebException.
You can then interrogate the ResponseStream and see what error you are actually getting back and
fix any other issues you might run into!

As always, Enjoy!
Chris

Follow me on twitter!