---
title: "カスタムRESTデータフェッチャーを使った辞書データの取得"
slug: "fetch-dictionary-data-using-a-custom-rest-data-fetcher"
abstract: "JSS Dictionary APIとカスタムRESTデータフェッチャーを使ってSitecore辞書データを取得する方法の例です。"
---
# カスタムRESTデータフェッチャーを使った辞書データの取得

RestDictionaryServiceConfig型はdataFetcherプロパティを受け入れます。このプロパティを使ってカスタムデータフェッチャーを辞書サービスのインスタンスに渡すことができます。デフォルトでは、JSS REST辞書サービスはaxiosを使用します。

> !注この例は、アプリケーションのルートディレクトリにファイルを作成し、同じディレクトリにconfig.jsファイルがあることを前提としています。プロジェクトのセットアップに合わせてインポート文を調整してください。

カスタムデータフェッチャーでREST辞書サービスを使用するには:

1.  dictionary-service.tsファイル内で、RestDictionaryServiceクラスのインスタンスを作成し、構成オブジェクトを提供します:
    
    import { AxiosResponse } from 'axios';
    import {
     AxiosDataFetcher,
     RestDictionaryService,
     DictionaryServiceData
    } from '@sitecore-jss/sitecore-jss';
    import config from './config';
    
    // define your custom data fetcher
    function dataFetcher(url: string, data?: unknown): Promise<AxiosResponse<DictionaryServiceData>> {
     return new AxiosDataFetcher().fetch(url, data);
    }
    
    export const dictionaryService = new RestDictionaryService({
     apiHost: config.sitecoreApiHost,
     apiKey: config.sitecoreApiKey,
     siteName: config.jssAppName,
     // provide your custom data fetcher to the service instance
     dataFetcher
    });
    
2.  新しい辞書サービスのインポートと利用:
    
    import { dictionaryService } from './dictionary-service';
    
    const language = 'en';
    
    dictionaryService.fetchDictionaryData(language).then(data => {
     // do something with the data
    });