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.
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:
The precondition to use the class is to create an instance of the REST configuration class in JavaScript.
Example: var RESTConfiguration = new RESTConfigurationClass();
Example of the class instance in JavaScript:
{ 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() {...} ... }
There exist two pipelines and one ISML module that can be used to set generally needed server configurations in the RESTConfiguration
automatically.
ProcessRESTConfiguration-GetProperties
ProcessRESTConfiguration-CreateToken
RESTConfiguration
.RESTConfiguration
and set all configurations in it.After using the related pipeline calls above it is possible to use exactly the following code snippet in your template.
<!-- 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>
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) value
(string|object) Returns
var RESTConfiguration = new RESTConfigurationClass(); RESTConfiguration.set("myIndex", "This is the value for myIndex."); RESTConfiguration.set("myIndexWithAnJSONObject", { });
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) Returns
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" } */
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:
Returns
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/"
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:
Returns
var RESTConfiguration = new RESTConfigurationClass(); var url = RESTConfiguration.getRESTUrl(); // Result e.g.: "https://localhost:443/INTERSHOP/rest/WFS/inSPIRED-inTRONICS_Business-Site/smb-responsive"
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:
Returns
var RESTConfiguration = new RESTConfigurationClass(); var url = RESTConfiguration.getStaticUrl(); // Result e.g.: "/INTERSHOP/static/WFS/inSPIRED-inTRONICS_Business-Site/smb-responsive/-/en_US/"
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:
Returns
var RESTConfiguration = new RESTConfigurationClass(); var host = RESTConfiguration.getRESTClientHost(); // Result e.g.: "/INTERSHOP/rest/WFS/"
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:
Returns
var RESTConfiguration = new RESTConfigurationClass(); var prefix = RESTConfiguration.getRESTClientPrefix(); // Result e.g.: "inSPIRED-inTRONICS_Business-Site/smb-responsive"
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:
Returns
var RESTConfiguration = new RESTConfigurationClass(); var token = RESTConfiguration.getAuthenticationToken(); // Result e.g.: "demo@PLAIN:Tqdu+K1K6+c=|VDcwS0RnQVZJcXNBQUFGV0Y0R3owQWM0QDE0Njk3OTgyNjY2Mzg="
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
Returns
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"
Getter method to return the current locale string.
Description:
Get the current locale string.
Parameter List:
rewrite
en_EN
to en-EN.
Returns
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"
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:
Returns
var RESTConfiguration = new RESTConfigurationClass(); var lang = RESTConfiguration.getLang(); // Result e.g.: "en"
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
Returns
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"
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
locale
(optional)Returns
<!--- Get localization properties from server ---> RESTConfiguration.getLocalizationProperties('subscriptions').then(function(data) { /* Example for response data: { "en_EN": { "key1": "...", "key2": "...", ... } } */ });