Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/whitep4nth3r/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.
https://github.com/whitep4nth3r/contentful-graphql-vs-rest
contentful graphql rest
Last synced: 4 months ago
JSON representation
A look at the difference between how to fetch and render linked assets and entries in the Rich Text field in Contentful.
- Host: GitHub
- URL: https://github.com/whitep4nth3r/contentful-graphql-vs-rest
- Owner: whitep4nth3r
- License: mit
- Created: 2021-03-01T14:07:43.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-04-29T11:18:26.000Z (almost 4 years ago)
- Last Synced: 2024-05-01T17:36:08.081Z (9 months ago)
- Topics: contentful, graphql, rest
- Language: JavaScript
- Homepage:
- Size: 121 KB
- Stars: 8
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Rendering linked assets and entries in the Contentful Rich Text field
## [Read the accompanying blog post on contentful.com](https://www.contentful.com/blog/2021/04/14/rendering-linked-assets-entries-in-contentful/)
---
## Running the code on your local machine
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/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:
```bash
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.](https://nextjs-contentful-blog-starter.vercel.app/)
## Run the development server
```bash
npm run dev
# or
yarn dev
```## Making the API calls
Example code for the GraphQL API can be found in [pages/graphql](https://github.com/whitep4nth3r/contentful-graphql-vs-rest/blob/main/pages/graphql.js).
Example code for the REST API can be found in [pages/rest](https://github.com/whitep4nth3r/contentful-graphql-vs-rest/blob/main/pages/rest.js).
API calls are executed at build time in `getStaticProps()` on each page. Read more about [getStaticProps() in Next.js.](https://nextjs.org/docs/basic-features/data-fetching#getstaticprops-static-generation)
Both code examples use [@contentful/rich-text-react-renderer](https://www.npmjs.com/package/@contentful/rich-text-react-renderer) to render the Rich Text field nodes to React components.