Skip to content

Data Transformation

When fetching necessary data from the CaaS, the Frontend API Server automatically applies a transformation based on the raw result and sends it back to the client. However, there are certainly possible use cases that require a second fetch request, filtering or any other form of data transformation.

The DataTransformation namespace can be used to perform an asynchronous transformation of these three access points:

# findPage
GET /api/findPage?id=homepage&locale=en_GB&type=content

# findElement
GET /api/findElement?fsPageId=043e4967-27e8-4a49-b41a-ebc3da1505e5&locale=en_GB

# fetchNavigation
GET /api/fetchNavigation?locale=en_GB&initialPath=%2F

Scope

This code part is meant to be executed on server instances and therefore uses the Frontend API server module.

import { DataTransformer, FetchResponseItem, Transformer } from 'fcecom-frontend-api-server';

DataTransformer.registerTransformer(Transformer.FIND_PAGE, async (page: FetchResponseItem | null) => ({
  myOwnPageProperty: page,
}));

... which returns:

{
  "myOwnPageProperty": {
    // ...page or null
  }
}

Last update: February 26, 2024