@squiz/xaccel-data-fetcher
v1.13.1
Published
A helper function to grab data from endpoints.
Downloads
481
Maintainers
Keywords
Readme
Data Fetcher
Description
A utility for fetching an array of child assets from a root node using the Matrix Content API
See example.ts for working example implementation
import { MatrixApiAdapter, DataFetcher } from @squiz/xaccel-data-fetcher;
const matrixAdapter = new MatrixApiAdapter(rootNodeId, assetType, resultLimit, sortByOptions.name, sortOrderOptions.asc, customMap);
(async () => {
const getData = await DataFetcher(matrixAdapter, apiEndpoint, apiKey);
console.log(getData);
})();
MatrixApiAdapter
Class constructor that returns and transforms Matrix data
Usage
import { MatrixApiAdapter } from @squiz/xaccel-data-fetcher;
const matrixAdapter = new MatrixApiAdapter(rootNodeId, assetType, resultLimit, sortByOptions.name, sortOrderOptions.asc, customMap);
required arguments
- rootNodeId { Number = 4243 }
- assetType { String or Array for multiple = 'page_standard' or ['news_item','page_standard'] or even ['page_standard'] will be ok too }
optional arguments
- resultLimit { Number = 20 }
- sortBy { String of the following value }
- id
- type
- version
- name
- shortName
- statusId
- createdDate
- updatedDate
- publishedDate
- statusChangedDate
- sortOrder { String of the following value }
- asc
- desc
- customMap { Callback function to transform the raw data returned by the API }
DataFetcher
A function that takes an adapter, API endpoint URL and API key
Usage
import { DataFetcher } from @squiz/xaccel-data-fetcher;
(async () => {
const getData = await DataFetcher(matrixAdapter, apiEndpoint, apiKey);
})();
required arguments
- matrixAdapter { Matrix adapter }
- apiEndPoint { String }
Local Development
npm run start will run the example.ts file on Node and console log the returned data
For simple local development set up a .env file with the following variables and/or edit the example.ts file to your liking
CONTENT_API=" "
CONTENT_API_KEY=" "