Hello World SharePoint-Hosted app using REST api through JavaScript

Today, I will show you how to create simple hello world SharePoint-Hosted app using REST api through JavaScript.

REST api were supported in SharePoint 2010 as well but was pretty limited and was exposed through listdata.svc. In SharePoint 2013, listdata.svc is still supported but Microsoft has introduced whole new REST api exposed through client.svc. New RESTful apis are extremely powerful and let’s you do pretty much everything that you could do with CSOM.

Here is the code for hello world sample app using REST api.

$(document).ready(function () {
    $.ajax(
        {
            url: _spPageContextInfo.webServerRelativeUrl + "/_api/web/currentuser",
            type: "GET",
            headers: {
                "accept": "application/json;odata=verbose",
            },
            success : function(data) {
                $("#message").text("welcome " + data.d.Title);
            },
            failure : function(err) {
                $("#message").text(JSON.stringify(err));
            }
        });
});
Add a Comment

Recent Posts