Fetching content
Alokai integration for Contentful ships with a framework-agnostic Typescript SDK. You can use it to interact with Contentful Delivery API and fetch your content entries.
Fetching entry by ID
To fetch a single entry by ID, you can use the getEntry method.
import { sdk } from '~/sdk.config';
const entry = await sdk.contentful.getEntry('5wrUZjR3uaDNedfSmYRkkB');
Fetching entry collections
Alternatively, you can use the getEntries method. It should be your primary method for fetching content entries. It allows you to build sophisticated search queries and fetch a collection of entries.
import { sdk } from '~/sdk.config';
const entries = await sdk.contentful.getEntries({
content_type: 'page',
'fields.[<some_field>]': '<some_field_value>'
});
When working with the return value of the getEntries method, we recommend extracting the nested items
property from it. It will make things such as working with the Live Preview easier.
import { sdk } from '~/sdk.config';
const { items } = await sdk.contentful.getEntries({ ... });
Using Typescript IntelliSense
Thanks to the effort of the Contentful team and their amazing Typescript SDK, our SDK methods such as getEntries are fully typed. Therefore, building even the most sophisticated search queries can be a piece of cake with the Typescript IntelliSense in your IDE.