Utilities

Drupal State also exposes utility functions that can be used to interact with JSON:API endpoints even if you’d prefer to use an alternative state management solution.

import {
  fetchApiIndex,
  fetchJsonapiEndpoint,
  fetchToken,
  translatePath,
} from '@gdwc/drupal-state';

const apiIndexData = await fetchApiIndex(
  'https://dev-ds-demo.pantheonsite.io/jsonapi'
);
const recipes = await fetchJsonapiEndpoint(
  'https://dev-ds-demo.pantheonsite.io/en/jsonapi/node/recipe'
);

const tokenRequestBody = {
  grant_type: 'client_credentials',
  client_id: 'MY_ID',
  client_secret: 'MY_SECRET',
};
const tokenResponse = await fetchToken(
  'https://dev-ds-demo.pantheonsite.io/en/jsonapi/node/recipe',
  tokenfetchBody
);

const translatedPath = await translatePath(
  'https://dev-ds-demo.pantheonsite.io/router/translate-path',
  '/recipes/fiery-chili-sauce'
);