{"id":15101363,"url":"https://github.com/davidpett/ember-data-contentful","last_synced_at":"2025-10-08T08:32:25.280Z","repository":{"id":50916885,"uuid":"54563031","full_name":"davidpett/ember-data-contentful","owner":"davidpett","description":"Ember Data adapter for contentful.com","archived":true,"fork":false,"pushed_at":"2021-05-27T20:52:28.000Z","size":1692,"stargazers_count":34,"open_issues_count":9,"forks_count":17,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-14T06:19:32.245Z","etag":null,"topics":["contentful","ember","ember-addon","ember-data"],"latest_commit_sha":null,"homepage":"http://davidpett.github.io/ember-data-contentful/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davidpett.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-23T13:44:58.000Z","updated_at":"2024-05-30T02:37:43.000Z","dependencies_parsed_at":"2022-08-27T04:22:59.426Z","dependency_job_id":null,"html_url":"https://github.com/davidpett/ember-data-contentful","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidpett%2Fember-data-contentful","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidpett%2Fember-data-contentful/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidpett%2Fember-data-contentful/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidpett%2Fember-data-contentful/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidpett","download_url":"https://codeload.github.com/davidpett/ember-data-contentful/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235700110,"owners_count":19031668,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["contentful","ember","ember-addon","ember-data"],"created_at":"2024-09-25T18:21:22.238Z","updated_at":"2025-10-08T08:32:19.921Z","avatar_url":"https://github.com/davidpett.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/davidpett/ember-data-contentful.svg?branch=master)](https://travis-ci.org/davidpett/ember-data-contentful)\n[![npm version](https://badge.fury.io/js/ember-data-contentful.svg)](https://badge.fury.io/js/ember-data-contentful)\n[![Ember Observer Score](http://emberobserver.com/badges/ember-data-contentful.svg)](http://emberobserver.com/addons/ember-data-contentful)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com)\n[![FastBoot Ready](https://img.shields.io/badge/FastBoot-ready-brightgreen.svg)](http://ember-fastboot.com)\n# ember-data-contentful\n\nThis is an Ember Data adapter/serializer that uses the **READ ONLY** Content Delivery API from [contentful](http://contentful.com)\n\n## Setup in your app\n```sh\nember install ember-data-contentful\n```\n\nAfter installing the addon, configure your Contentful Space ID and Access Token inside `ENV` in `config/environment.js`:\n```js\ncontentful: {\n  space: 'YOUR-CONTENTFUL-SPACE',\n  accessToken: 'YOUR-CONTENTFUL-ACCESS-TOKEN',\n  previewAccessToken: 'YOUR-CONTENTFUL-PREVIEW-ACCESS-TOKEN',\n  usePreviewApi: false,\n  environment: 'OPTIONAL CONTENTFUL ENVIRONMENT NAME'\n}\n```\n\nYou can enable the Preview API for use in development in `config/environment.js`:\n\n```js\n  if (environment === 'development') {\n    // ...\n    \n    ENV.contentful.usePreviewApi = true;\n  }\n```\n\n### Contentful models\n\nIncluded are a few models to help with some of the default fields. Here is an example:\n\n```js\n// models/post.js\nimport Contentful from 'ember-data-contentful/models/contentful';\nimport attr from 'ember-data/attr';\nimport { belongsTo, hasMany } from 'ember-data/relationships';\n\nexport default Contentful.extend({\n  author: hasMany('author'),\n  body: attr('string'),\n  date: attr('date'),\n  featuredImage: belongsTo('contentful-asset'),\n  slug: attr('string'),\n  title: attr('string')\n});\n```\nwill give you the default fields of `contentType`, `createdAt`, and `updatedAt`.\n\nFor multi-word model names, you can name your Contentful model IDs with dashes (ie. `timeline-post`) make sure the `contentType` field is inferred correctly.\n\nFor any relationship property that is a Contentful Asset (image or other media file), use the `contentful-asset` model. i.e. `image: belongsTo('contentful-asset')` in order to get the asset correctly.\n\n### Adapters and serializers\n\nYou will also need to define an adapter and serializer for your model, so that Ember Data knows to fetch data from Contentful instead of your default backend.\n\n```js\n// app/adapters/post.js\nimport ContentfulAdapter from 'ember-data-contentful/adapters/contentful';\n\nexport default ContentfulAdapter.extend({});\n```\n\n```js\n// app/serializers/post.js\nimport ContentfulSerializer from 'ember-data-contentful/serializers/contentful';\n\nexport default ContentfulSerializer.extend({});\n```\n\nIf you are only using Contentful models, you can set these to `app/adapters/application.js` and `app/serializers/application.js` to apply for all models.\n\n## Usage\n\nOnce you have configured your tokens and created your models, you can use the normal Ember Data requests of `findRecord`, `findAll`, `queryRecord`, and `query`. For example:\n```js\nmodel() {\n  return this.store.findAll('project');\n}\n```\nor\n```js\nmodel(params) {\n  return this.store.findRecord('project', params.project_id);\n}\n```\n\nIf you want to use pretty urls and the `slug` field in contentful, you can make your query like so:\n```js\nmodel(params) {\n  return this.store.queryRecord('page', {\n    'fields.slug': params.page_slug\n  });\n},\nserialize(model) {\n  return { page_slug: get(model, 'slug') };\n}\n```\nand ensure that you declare your route in `router.js` like this:\n```js\nthis.route('page', { path: ':page_slug' });\n```\n\n## Previewing Content\n\nContentful provides a [Preview API](https://www.contentful.com/developers/docs/references/content-preview-api/) that allows you to preview unpublished content. In order to enable this, ensure you have your `previewAccessToken` configured in `config/environment.js` and enable the `usePreviewApi` property.\n\nFor more information on the contentful Content Delivery API and the available queries, look here: https://www.contentful.com/developers/docs/references/content-delivery-api/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidpett%2Fember-data-contentful","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidpett%2Fember-data-contentful","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidpett%2Fember-data-contentful/lists"}