I've just started with SharePoint, I've set up a website and now i'm wondering, how i can communicate with a REST Web Service with Sharepoint. What's best practice in this case?
2 Answers
For example it is easy to use Jquery to communicate with the web service:
// Getting list items based on ODATA Query
function getListItems(url, listname, query, complete, failure) {
// Executing our items via an ajax request
$.ajax({
url: url + "/_api/web/lists/getbytitle('" + listname + "')/items" + query,
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
complete(data); // Returns JSON collection
},
error: function (data) {
failure(data);
}
});
}
Please also read the 'Get to know the SharePoint 2013 REST service' article from Microsoft for all possibilities.
-
Can i define this function directly in a webpart or should this be in another file? Feb 18, 2016 at 10:03
-
The goal of this
http://www.codeproject.com/Articles/990131/CRUD-Operation-to-List-Using-SharePoint-Rest-API
is to provide a complete idea about CRUD (create, read, update and delete) operation in a list of SharePoint 2013 using REST API.
Good Practices and all basic operations are covered in this link.
To perform Rest Calls you may need to add JQuery Reference on the Page as well.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>