response.data.item.elements.headline.value
.
In a more complicated scenario, this approach becomes cumbersome. It forces you to remember the JSON structure of your content items and the codenames of your content elements.
To make this easier, use a Delivery SDK to map the retrieved content items to their strongly typed models.
body_text
becomes property bodyText
.// Tip: Find more about JS/TS SDKs at https://kontent.ai/learn/javascript
import { IContentItem, Elements } from '@kontent-ai/delivery-sdk';
/**
* Generated by '@kontent-ai/model-generator@5.2.0'
* Note: Element comments were omitted for brevity.
*/
export type Homepage = IContentItem<{
headline: Elements.TextElement;
body_text: Elements.RichTextElement;
picture: Elements.AssetsElement;
}>;
npm i @kontent-ai/model-generator -g
kontent-generate --environmentId=<YOUR_ENVIRONMENT_ID> --apiKey=<YOUR_MANAGEMENT_API_KEY>