Fetch dictionary data with the JSS REST Dictionary Service
Current version: 20.x
To invoke the REST Dictionary Service from a JSS application, use the JSS RestDictionaryService
:
Note
This example assumes you create the files in the /src
directory of the project, and that you have a config.js
file or config.ts
file in the /src/temp
directory. Adjust the import statements as necessary to reflect your project's setup.
To fetch dictionary data with the JSS REST Dictionary Service:
-
In a new
dictionary-service.ts
file, create an instance of theRestDictionaryService
class and provide the configuration object:RequestResponseimport { RestDictionaryService } from '@sitecore-jss/sitecore-jss'; import config from 'temp/config'; export const dictionaryService = new RestDictionaryService({ apiHost: config.sitecoreApiHost, apiKey: config.sitecoreApiKey, siteName: config.jssAppName, });
-
In the file where you want to fetch the data, import and use your new dictionary service instance:
RequestResponseimport { dictionaryService } from './dictionary-service'; const language = 'en'; dictionaryService.fetchDictionaryData(language).then(data => { // do something with the data });