Simple REST for SharePoint

There are many ways of getting the data from SharePoint to use in web parts, the first approach I ever took to creating a web part was to use the ListData.svc. With JavaScript I was able to grab data I needed to create a web part that produced a set of links (My first web part was slightly boring). If you enter the service into your browser, it will give you the lists you have access to.
https://www.contoso.com/_vti_bin/ListData.svc
Then find the list you are wanting to draw your data from and put it at the end of your url.
http://www.contoso.com/_vti_bin/ListData.svc/FavouriteBooks
Of course your site and list name will be different from the ones I’ve used as an example but in this instance it would return the data on the items in the FavouriteBooks list. Using this you can then run code against the data to pull out what you are trying to fetch.
This is a very simple rest call, if you set the SiteName to “” it will then run this code against the root of your site.
var SiteName = //Name of your SP site
var ListName = //Name of your SP list
 
$.getJSON(SiteName +  “/_vti_bin/ListData.svc/” + ListName, function (data) {
        $(data.d.results).each(function (index, value) {
            Value.title;
            Value.description;
            });
    });
The above JavaScript will return the title and description of each item from within your list, it doesnt do anything with it but if you were to have a breakpoint next to the returned values and then type them into the console, you would see the value returned.

Leave a Reply

Your email address will not be published. Required fields are marked *