Skip to content

ShareCoffee.REST.reqwest

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

reqwest is a small but powerful lib for executing requests. It has nearly no footprint, which makes it one of my fav. libraries available here on github. ShareCoffee can also provide pre-configured objects for executing REST queries using reqwest!

HostWeb - AppWeb

ShareCoffee is offering both, interaction with the AppWeb and interactions with the HostWeb. If you pass a HostWebUrl to any for.reqwest() 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.RequestProperties. You can either create a new instance by using the constructor ShareCoffee.REST.RequestProperties() 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, onSuccess, onError);
/// Create a property-object by using JSON syntax
var properties2 = { url: 'web/title')

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

description: TODO

Usage

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

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

description: TODO

Usage

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

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

description: TODO

Usage

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

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

description: TODO

Usage

reqwest(ShareCoffee.REST.build.delete.for.reqwest({url: "web/lists('" + customListId + "')",
  onSuccess: onListDeleted,
  onError: onError}));

Clone this wiki locally