Skip to content

ShareCoffee.REST.jQuery

Thorsten Hans edited this page Jan 16, 2014 · 5 revisions

jQuery is everywhere, therefor is ShareCoffee offering methods to easily create configuration objects which can easily be passed to jQuery's $.ajax() method.

HostWeb - AppWeb

ShareCoffee is offering both, interaction with the AppWeb and interactions with the HostWeb. If you pass a HostWebUrl to any for.jQuery() call, ShareCoffee will create a configuration-object which allows HostWeb-Access.

Configuring Requests

Each of the following methods is configured by a single parameter of type ShareCoffee.REST.jQueryProperties. You can either create a new instance by using the constructor ShareCoffee.REST.jQueryProperties() or you can pass a JSON object with corresponding properties.

/// Create property-object by using the constructor
var properties = new ShareCoffee.REST.RequestProperties(url, payload, hostWebUrl, eTag);
/// Create a property-object by using JSON syntax
var properties2 = { url: 'web/title' };

Reading Elements using ShareCoffee.REST.build.read.for.jQuery()

description: TODO

Usage

$.ajax(ShareCoffee.REST.build.read.for.jQuery({ url: "web/lists/?$select=Title,Id" }))
      .done(onListsLoaded)
      .fail(onError);

Creating Elements using ShareCoffee.REST.build.create.for.jQuery()

description: TODO

Usage

var payload = {
  '__metadata': { 'type': 'SP.List' },
  'AllowContentTypes': true,
  'BaseTemplate': 100,
  'ContentTypesEnabled': true,
  'Description': 'My list created by REST',
  'Title': "Thorstens List"
};
$.ajax(ShareCoffee.REST.build.create.for.jQuery({url: "web/lists/", payload: payload}))
  .done(onListCreated)
  .fail(onError);

Updating Elements using ShareCoffee.REST.build.update.for.jQuery()

description: TODO

Usage

var payload = {
  '__metadata': { 'type': 'SP.List' },
  'Title': 'CHANGED BY REST - Thorstens list'
};
$.ajax(ShareCoffee.REST.build.update.for.jQuery({url: "web/lists('" + customListId + "')", payload: payload}))
  .done(onListUpdated)
  .fail(onError);

Deleting Elements using ShareCoffee.REST.build.delete.for.jQuery()

description: TODO

Usage

$.ajax(ShareCoffee.REST.build.delete.for.jQuery({url: "web/lists('" + customListId + "')"}))
  .done(onListDeleted)
  .fail(onError);