Namespace: rest

rest

Methods

(static) get(url, config) → {Promise.<object>}

Rest API get helper. Uses sane defaults to speak to the API. Additional configuration can be passed with the config argument.
Parameters:
Name Type Description
url string an SP endpoint
config object additional configuration
Source:
Returns:
a promise that resolves to the response data
Type
Promise.<object>
Example
sputils.rest.get('/_api/web/lists').then(function (data) {
  $.each(data.d.results, function (idx,el) {
    console.log(el);
  });
});

(static) post(url, data, config) → {Promise.<object>}

Rest API post helper. Uses sane defaults to speak to the API. Additional configuration can be passed with the config argument.
Parameters:
Name Type Description
url string an SP endpoint
data object the payload
config object additional configuration
Source:
Returns:
a promise that resolves to the response data
Type
Promise.<object>
Example
var data = {
  Title: 'REST API FTW',
  __metadata: { type: 'SP.Data.AnnouncementsListItem'}
};

sputils.rest.post("/_api/Web/Lists/getByTitle('Announcements')/", data)
  .then(function (data) { console.log(data) });

(static) unwrapResults(object) → {Promise.<object>}

Results from the standard SharePoint REST APIs come wrapped in objects. This convenience function unwraps them for you. See example use.
Parameters:
Name Type Description
object object raw SP API response data
Source:
Returns:
unwrapped SP API data
Type
Promise.<object>
Example
sputils.rest.get('/_api/web/lists')
  .then(sputils.rest.unwrapResults)
  .then(function (data) {
    sputils.fjs.each(function (el, idx) {
      console.log(el);
    }, data);
  });