Document Properties
Kbid28013T
Last Modified24-Jun-2020
Added to KB23-Sep-2016
Public AccessEveryone
StatusOnline
Doc TypeGuidelines, Concepts & Cookbooks
Product
  • ICM 7.8
  • ICM 7.9
  • ICM 7.10

Concept - JavaScript REST Configuration

1 Introduction

The REST configuration class RESTConfiguration is a JavaScript based class to handle any configurations which can be used for REST.
The idea behind this class is to have one place to provide any JavaScript configurations related to REST.

1.1 References

The REST configuration class is used by Intershop JavaScript REST Client as well as each Handlebars controllers.

More information on the JavaScript Intershop REST Client can be found here:

2 Precondition

  1. The precondition to use the class is to create an instance of the REST configuration class in JavaScript.
    Example: var RESTConfiguration = new RESTConfigurationClass();

  2. Example of the class instance in JavaScript:

    Example for the instance of the configuration class with saved values
    {
    	AuthenticationToken: "demo@PLAIN:Tqdu+K1K6+c=|xxxxxxxxxxxxxxxxxx=",
    	BusinessPartnerNo: "fbirdo",
    	CurrencyCode: "USD",
    	CustomerNo: "AgroNet",
    	CustomerTypeID: "SMB",
    	Domain: "inSPIRED-inTRONICS_Business-Site",
    	LocaleID: "en_US",
    	Login: "fbirdo@test.intershop.de",
    	MoneyFormat: {
    		MONEY_LONG: {
    			decimal: ".",
    			format: {
    				neg: "$ - %v",
    				pos: "$ %v"
    			},
    			grouping: 3,
    			precision: 2,
    			symbol: "$",
    			thousand: ","
    		},
    		MONEY_SHORT: { ... },
    		MONEY_INPUT: { ... },
    		...
    	},
    	ServerGroup: "WFS",
    	URLIdentifier: "smb-responsive",
    	URLMappingPipelineWebadapter: "/INTERSHOP/web",
    	URLMappingRESTWebadapter: "/INTERSHOP/rest",
    	URLMappingStaticWebadapter: "/INTERSHOP/static",
    	WebServerSecureURL: "https://localhost:443",
    	WebServerURL: "http://localhost:80",
    	
    	method1() {...}
    	method2() {...}
    	method3() {...}
    	...
    }

3 Set All Available Generally Needed Configurations Automatically

There exist two pipelines and one ISML module that can be used to set generally needed server configurations in the RESTConfiguration automatically.

  1. Use these pipelines to get all configurations from server.
    ProcessRESTConfiguration-GetProperties
    ProcessRESTConfiguration-CreateToken
  2. To set all server configurations by the pipelines an ISML module is available to set all configuration values within the RESTConfiguration.
    The module ISRESTConfiguration (not strict) generates the JavaScript code to create the JavaScript instance of the RESTConfiguration and set all configurations in it.
  3. After using the related pipeline calls above it is possible to use exactly the following code snippet in your template.

    ISML Module: ISRESTConfiguration
    <!-- 
    	No parameters are needed for this module 
    	All needed configurations will get by an internal pipeline call within the module.
    -->
    <isinclude template="modules/rest/Modules">
    <ISRESTConfiguration>

4 Methods

4.1 set

set( <index>, <value> )

Setter for any REST configurations in the instance of the RESTConfigurationClass.

Description:

Set an any REST configuration parameter within the REST configuration instance.

Parameter List:

  • index (string)
    String with the name of the index for the saved configuration value.
  • value (string|object)
    String or object with the value for the saved configuration index.

Returns

  • none
Example
var RESTConfiguration = new RESTConfigurationClass();
RESTConfiguration.set("myIndex", "This is the value for myIndex.");

RESTConfiguration.set("myIndexWithAnJSONObject", {
	
});

4.2 get

get( <index> )

Getter for any saved REST configurations in the instance of the RESTConfigurationClass.

Description:

Get a specific REST configuration parameter from the REST configuration instance.

Parameter List:

  • index (string)
    String with the name of the index for the saved configuration value.

Returns

  • Returns the value of the saved configuration parameter by the name of the configuration index.
Example
var RESTConfiguration = new RESTConfigurationClass();
RESTConfiguration.set("myIndex", "This is the value for myIndex.");
RESTConfiguration.get("myIndex");
 
// Result of the getter: "This is the value for myIndex."
 
RESTConfiguration.set("myIndex1", {
	"param1": 123,
	"param2": "Parameter 2"
});
RESTConfiguration.get("myIndex1");
 
/*Result of the getter is the saved JSON object:
{
	"param1": 123,
	"param2": "Parameter 2"
}
*/

4.3 getWebUrl

getWebUrl()

Getter method to return the full WebShop-URL.

Description:

Get the full WebShop-URL based on some saved configuration like WebServerSecureURL , URLMappingPipelineWebadapter , ServerGroup , Domain .. etc...

Parameter List:

  • none

Returns

  • Get the full WebShop-URL as a string.
Example
var RESTConfiguration = new RESTConfigurationClass();
var url = RESTConfiguration.getWebUrl();

// Result e.g.: "https://localhost:443/INTERSHOP/web/WFS/inSPIRED-inTRONICS_Business-Site/en_US/smb-responsive/USD/"

4.4 getRESTUrl

getRESTUrl()

Getter method to return the full WebShop-REST-URL.

Description:

Get the full WebShop-REST-URL based on some saved configuration like WebServerSecureURL , URLMappingPipelineWebadapter , ServerGroup , Domain .. etc...

Parameter List:

  • none

Returns

  • Get the full WebShop-REST-URL as a string.
Example
var RESTConfiguration = new RESTConfigurationClass();
var url = RESTConfiguration.getRESTUrl();

// Result e.g.: "https://localhost:443/INTERSHOP/rest/WFS/inSPIRED-inTRONICS_Business-Site/smb-responsive"

4.5 getStaticUrl

getStaticUrl()

Getter method to return the WebShop-URL to the static files.

Description:

Get the full WebShop-URL to the directory of all static files based on some saved configuration like WebServerSecureURL, URLMappingPipelineWebadapter, ServerGroup, Domain .. etc...

Parameter List:

  • none

Returns

  • Get the full WebShop-URL to all satic files as a string.
Example
var RESTConfiguration = new RESTConfigurationClass();
var url = RESTConfiguration.getStaticUrl();

// Result e.g.: "/INTERSHOP/static/WFS/inSPIRED-inTRONICS_Business-Site/smb-responsive/-/en_US/"

4.6 getRESTClientHost

getRESTClientHost()

Getter method to return the host part of the WebShop REST client URL.

Description:

Get the host part of the WebShop REST client URL based on some saved configuration like URLMappingRESTWebadapter and ServerGroup.
This part of the URL is needed from the JavaScript Intershop REST Client.

Parameter List:

  • none

Returns

  • Get the URL part as a string.
Example
var RESTConfiguration = new RESTConfigurationClass();
var host = RESTConfiguration.getRESTClientHost();

// Result e.g.: "/INTERSHOP/rest/WFS/"

4.7 getRESTClientPrefix

getRESTClientHost()

Getter method to return the REST URL prefix part of the WebShop REST client URL.

Description:

Get the prefix part of the WebShop REST client URL based on some saved configuration like Domain and URLIdentifier.
This part of the URL is needed from the JavaScript Intershop REST Client.

Parameter List:

  • none

Returns

  • Get the URL part as a string.
Example
var RESTConfiguration = new RESTConfigurationClass();
var prefix = RESTConfiguration.getRESTClientPrefix();

// Result e.g.: "inSPIRED-inTRONICS_Business-Site/smb-responsive"

4.8 getAuthenticationToken

getRESTClientHost()

Getter method to return the Authorization-Token for all REST calls.

Description:

Get the Authorization-Token for all REST calls based on the logged in customer.
The Authorization-Token is needed from the JavaScript Intershop REST Client.

Parameter List:

  • none

Returns

  • Get the Authorization-Token as a string.
Example
var RESTConfiguration = new RESTConfigurationClass();
var token = RESTConfiguration.getAuthenticationToken();

// Result e.g.: "demo@PLAIN:Tqdu+K1K6+c=|VDcwS0RnQVZJcXNBQUFGV0Y0R3owQWM0QDE0Njk3OTgyNjY2Mzg="

4.9 getCustomerUrlPart

getCustomerUrlPart()

Getter method to return a part of the URL with all needed customer information for all REST calls.

Description:

Get the part of the URL with all needed customer information for all REST calls based on the logged in customer.
The method consideres the current channel type like B2C or B2B.

Parameter List:

  • accountAdmin (optional) - true|false
    Defines whether the current user is an account admin.

Returns

  • Get the REST URL part as a string.
Example
var RESTConfiguration = new RESTConfigurationClass();

var urlPart = RESTConfiguration.getCustomerUrlPart();
// Result for B2C e.g.: "customers/Patricia"
// Result for B2B e.g.: "customers/AgroNet/users/fbirdo@test.intershop.de"
 
var urlPart = RESTConfiguration.getCustomerUrlPart(true);
// Result for B2B e.g.: "customers/AgroNet"

4.10 getLocale

getLocale( <rewrite> )

Getter method to return the current locale string.

Description:

Get the current locale string. 

Parameter List:

  • rewrite
    Defines whether the locale string should be rewrite from en_EN to en-EN.

Returns

  • Get the current locale as a string.
Example
var RESTConfiguration = new RESTConfigurationClass();
var locale1 = RESTConfiguration.getLocale();
var locale2 = RESTConfiguration.getLocale(true);

// Result locale1 e.g.: "en_EN"
// Result locale2 e.g.: "en-EN"

4.11 getLang

getLang()

Getter method to return the current language.

Description:

Get the current language as a string.
The language is the first part of the saved current locale like "en_EN".

Parameter List:

  • none

Returns

  • Get the current language as a string.
Example
var RESTConfiguration = new RESTConfigurationClass();
var lang = RESTConfiguration.getLang();

// Result e.g.: "en"

4.12 getLocalizationsUrl

getLocalizationsUrl( <id> )

Getter method to return the URL to the JavaScript side localization files.

Description:

Get the URL to the JavaScript side localization files as a string.
All files with JavaScript side localization keys have to exist in the JSON file like this format.
The part of the filename with the current locale will be set automatically by the saved locale in the RESTConfiguration.

Example:

.../localizations/<id>-<localeID>.json

.../localizations/subscriptions-de_DE.json
.../localizations/subscriptions-en_US.json

Parameter List:

  • id
    The parameter defines the name of the localizations file.
    Filename format: <id>-<localeID>.json

Returns

  • Get the full URL as a string.
Example
var RESTConfiguration = new RESTConfigurationClass();
var url1 = RESTConfiguration.getLocalizationsUrl('subscriptions');
var url2 = RESTConfiguration.getLocalizationsUrl('basket');

// Result url1 e.g.: "/INTERSHOP/static/WFS/inSPIRED-inTRONICS_Business-Site/smb-responsive/-/en_US/js/localizations/subscriptions-en_US.json"
// Result url2 e.g.: "/INTERSHOP/static/WFS/inSPIRED-inTRONICS_Business-Site/smb-responsive/-/en_US/js/localizations/basket-en_US.json"

4.13 getLocalizationProperties

getLocalizationProperties( <topic>, <locale> )

Getter method to return server side localization properties.

Description:

Triggers an ajax request to pipeline ViewLocalization-Get.
The response is a JSON object with all matched server side localization properties where the topic parameter string is found in property keys.

Parameter List:

  • topic
    The parameter defines a string as a localization key filter for which localization properties should be searched
    For example: If the parameter topic is set on subscriptions it will found all localization properties where the parameter is found in property key string. (e.g.: "account.subscriptions.filter.sortby")
  • locale (optional)
    Defines a search filter for which language the localization properties will be searched.

Returns

  • Get a jQuery promise with all response data as a JSON object.
Example
<!--- Get localization properties from server --->
RESTConfiguration.getLocalizationProperties('subscriptions').then(function(data) {
	
	/* 
		Example for response data:
		{
			"en_EN": {
				"key1": "...",
				"key2": "...",
				...
			}
		}
	*/
		
});

Disclaimer

The information provided in the Knowledge Base may not be applicable to all systems and situations. Intershop Communications will not be liable to any party for any direct or indirect damages resulting from the use of the Customer Support section of the Intershop Corporate Web site, including, without limitation, any lost profits, business interruption, loss of programs or other data on your information handling system.

Customer Support
Knowledge Base
Product Resources
Support Tickets