contentful-graphql-vs-rest

A look at the difference between how to fetch and render linked assets and entries in the Rich Text field in Contentful.

MIT License

Stars
8

Rendering linked assets and entries in the Contentful Rich Text field

Read the accompanying blog post on contentful.com


Running the code on your local machine

This is a Next.js project bootstrapped with create-next-app.

Getting Started

Fork this repository to your GitHub account, and clone it to your local machine using git or the GitHub CLI.

Install dependencies:

npm install
# or
yarn install

At the root of your project, create an .env.local file and copy the contents from .env.local.example. This will provide you with a connection to an example Contentful space. You can view the live example website for this space here.

Run the development server

npm run dev
# or
yarn dev

Making the API calls

Example code for the GraphQL API can be found in pages/graphql.

Example code for the REST API can be found in pages/rest.

API calls are executed at build time in getStaticProps() on each page. Read more about getStaticProps() in Next.js.

Both code examples use @contentful/rich-text-react-renderer to render the Rich Text field nodes to React components.