ISHRestClient
is a JavaScript based class to handle REST calls. It allows to execute any REST call and provide useful utility methods to prepare a JSON REST response.
ISHRestClient
- Intershop REST ClientTo configure the ISHRestClient
utilize the following methods:
client.host('/INTERSHOP/rest/WFS')
;client.prefix('inSPIRED-inTRONICS_Business-Site/-')
;client.token('demo@PLAIN:lcmI551YIjY=|VDcwS0RnQVZJcXNBQUFGV0Y0R3owQWM0QDE0NjkxODA0NTQ2NDU=')
;client.auth('Basic xxxxxxxxx=')
;Set the basic authentication for the REST request in the Intershop REST client.
The basic authentication is only needed when the authentication token is not available.
client.customer('customers/AgroNet/users/fbirdo@test.intershop.de')
;Automatic REST Client Configuration
If there is a RESTConfiguration instance available the ISHRestClient
implementation sets the related configuration values automatically.
More information on the RESTConfiguration:
The precondition to use the class is to create an instance of the REST client.
var client = new ISHRestClient();
Setter and Getter for REST call host URL.
Description:
Set the Intershop host part of the REST URL in the Intershop REST client.
The method is chainable.
Parameter List:
Returns
Example
var client = new ISHRestClient(); client.host('/INTERSHOP/rest/WFS'); // Setter client.host(); // Getter
Setter and Getter for REST call prefix URL.
Description:
Set the rest prefix part of the REST URL with the Domain and URLIdentifier in the Intershop REST client.
The method is chainable.
Parameter List:
Returns
Example
var client = new ISHRestClient(); client.prefix('inSPIRED-inTRONICS_Business-Site/-'); // Setter client.prefix(); // Getter
Setter and Getter for REST call header data.
Description:
Set all defined header data for the REST request in the Intershop REST client.
The method is chainable.
Parameter List:
Returns
Example
var client = new ISHRestClient(); client.header({ "Accept": "application/json", ... }); // Setter client.header(); // Getter
Setter and Getter for REST call request data.
Description:
Set the rest prefix part of the REST URL with the Domain and URLIdentifier in the Intershop REST client.
The method is chainable.
Parameter List:
Returns
Example
var client = new ISHRestClient(); client.data({ "param1": "...", "param2": "...", ... }); // Setter client.data(); // Getter
Getter for full REST request URL.
Description:
Get the full REST request URI with base URI and also the complete resource path.
Parameter List:
Returns
Example
var client = new ISHRestClient(); client.uri();
Setter and Getter for REST call basic authorization.
Description:
Set the basic authorization (e.g., 'Basic xxxxxxxxx=') for the REST call.
Parameter List:
Returns
Example
var client = new ISHRestClient(); client.auth('Basic xxxxxxxxx='); // Setter client.auth(); // Getter
Setter and Getter for REST call authentication token.
Description:
Set the authentication token (e.g., 'demo@PLAIN:lcmI551YIjY=|xxxxxxxxxxxxx=') for the REST call.
Parameter List:
Returns
Example
var client = new ISHRestClient(); client.token('demo@PLAIN:lcmI551YIjY=|VDcwS0RnQVZJcXNBQUFGV0Y0R3owQWM0QDE0NjkxODA0NTQ2NDU='); // Setter client.token(); // Getter
Setter and Getter for REST call error handler functions.
Description:
Register a handler function for a specific Ajax error code.
Parameter List:
Returns
Example
var client = new ISHRestClient(); client.error('401', function(jqXHR, textStatus, errorThrown) { // ... customized code }); client.error(); // Getter
Setter and Getter for REST call customer url part.
Description:
Set the URL part with the related customer for whom the request is called.
The method is chainable.
Parameter List:
Returns
Example
var client = new ISHRestClient(); client.customer('customers/AgroNet/users/fbirdo@test.intershop.de'); // Setter for B2B client.customer('customers/Patricia'); // Setter for B2C client.customer(); // Getter
Calls a request with method 'POST'.
Description:
Calls a Ajax request with method 'POST' with all set options and headers.
The method is chainable.
Parameter List:
data()
will be used)Returns
jQuery.ajax()
promise object.then()
after the REST request.Example
var client = new ISHRestClient(); client.create('/recurringorders', { "param1": "...", ... }).then(function(data) { // ... custom code with response data });
Calls a request with method 'GET'.
Description:
Calls a Ajax request with method 'GET' with all set options and headers.
The method is chainable.
Parameter List:
Returns
jQuery.ajax()
promise object.then()
after the REST request.Example
var client = new ISHRestClient(); client.get('/recurringorders').then(function(data) { // ... custom code with response data });
Calls a request with method 'PUT'.
Description:
Calls a Ajax request with method 'PUT' with all set options and headers.
The method is chainable.
Parameter List:
data()
will be used)Returns
jQuery.ajax()
promise object.then()
after the REST request.Example
var client = new ISHRestClient(); client.update('/recurringorders', { "param1": "...", ... }).then(function(data) { // ... custom code with response data });
Calls a request with method 'DELETE'.
Description:
Calls a Ajax request with method 'DELETE' with all set options and headers.
The method is chainable.
Parameter List:
Returns
jQuery.ajax()
promise object.then()
after the REST request.Example
var client = new ISHRestClient(); client.del('/recurringorders/123456789').then(function(data) { // ... custom code with response data });
Calls a request with method 'DELETE'.
Description:
Resolve all links in the response and calls separate get requests for each links.
The result is a collection with the response of each link requests.
The method is chainable.
Parameter List:
Returns
jQuery.ajax()
promise object.then()
after the REST request.Example
var client = new ISHRestClient(); client.getElements('/recurringorders').then(function(data) { // ... custom code with all response data of all each link requests });
{ "elements": [ { "type": "Link", "uri": "inSPIRED-inTRONICS_Business-Site/-/customers/AgroNet/users/fbirdo@test.intershop.de/quoterequests/OmwKDgAhF5IAAAFTgy8bsDHK", "title": "OmwKDgAhF5IAAAFTgy8bsDHK" }, { "type": "Link", "uri": "inSPIRED-inTRONICS_Business-Site/-/customers/AgroNet/users/fbirdo@test.intershop.de/quoterequests/brcKDgAhwXEAAAFTti0bsDHO", "title": "brcKDgAhwXEAAAFTti0bsDHO" } ], "type": "ResourceCollection", "name": "quoteRequests" }
Get an optimized collection of all given response attributes.
Description:
The method converts the data structure of all given attributes from the response to an simple collection with all attributes in a key value map.
The method is chainable.
Parameter List:
attributes (array)
Array with all given response attributes in form of the following
{ "elements":[ { "type":"Link", "attributes":[ { "name":"number", "type":"String", "value":"0000009" }, { "name":"creationDate", "type":"Long", "value":1469533578641 }, { "name":"startDate", "type":"Long", "value":1469533578641 }, { "name":"endDate", "type":"Long", "value":1469533578641 }, { "name":"interval", "type":"Period", "value":"P3M" }, { "name":"active", "type":"Boolean", "value":false }, { "name":"itemCount", "type":"Integer", "value":3 }, { "name":"total", "type":"MoneyRO", "value":{ "type":"Money", "value":430.37, "currencyMnemonic":"USD" } }, { "name":"lastOrderDate", "type":"Long", "value":1469533578641 }, { "name":"buyer", "type":"String", "value":"Fritz Birdo" } ], "uri":"inSPIRED-inTRONICS_Business-Site/smb-responsive/customers/AgroNet/users/fbirdo@test.intershop.de/recurringorders/recurringOrderID9", "title":"recurringOrderID9" } ] }
Returns
Returns the response as a jQuery.ajax()
promise object.
So it is possible to use the chainable method then()
after the REST request.
{ "elements": [ { "attributes": [ { "active": true, "buyer": "Fritz Birdo", "creationDate": 1469533578641, "endDate": 1469533578641, "interval": "P14D", "itemCount": 14, "lastOrderDate": 1469533578641, "number": "0000010", "startDate": 1469533578641 }, { "active": false, "buyer": "Fritz Birdo", "creationDate": 1469533578641, "endDate": 1469533578641, "interval": "P2W", "itemCount": 7, "lastOrderDate": 1469533578641, "number": "0000021", "startDate": 1469533578641 } } } ] }
Example
var client = new ISHRestClient(); client.get('/recurringorders').then(function(data) { var model = client.getReducedAttrCollection(data.elements); });
(PRIVATE) - Triggers the calling of the REST call by jQuery.ajax()
Description:
Calls the jQuery Ajax request with all configurations.
This method will only be called internal (private) and will be called from the methods create, update, get or delete.
The method is chainable.
Parameter List:
Returns
jQuery.ajax()
promise object.then()
after the REST request.