contentful-super-agent
v0.2.3
Published
Client for Contentful's Content Delivery API
Downloads
3
Readme
Javascript SDK for Contentful's Content Delivery API.
About
Contentful is a content management platform for web applications, mobile apps and connected devices. It allows you to create, edit & manage content in the cloud and publish it anywhere via a powerful API. Contentful offers tools for managing editorial teams and enabling cooperation between organizations.
Features
- Content retrieval through Contentful's Content Delivery API.
- Synchronization
- Localization support
- Link resolution
Supported environments
Browsers and Node.js:
- Chrome
- Firefox
- IE11 / Edge
- Safari
- node.js (0.10, iojs-3.x, 4.x, 5.x)
Other browsers should also work, but at the moment we're only running automated tests on the browsers and Node.js versions specified above.
Getting started
In order to get started with the Contentful JS SDK you'll need not only to install it, but also to get credentials which will allow you to have access to your content in Contentful.
Installation
In node, using npm:
npm install contentful
Or, if you'd like to use a standalone built file you can use the following script tag or just download it from unpkg, under the browser-dist
directory:
<script src="https://unpkg.com/contentful@latest/browser-dist/contentful.min.js"></script>
It is not recommended to use the above URL for production.
Using contentful@latest
will always get you the latest version, but you can also specify a specific version number:
<script src="https://unpkg.com/[email protected]/browser-dist/contentful.min.js"></script>
Check the releases page to know which versions are available.
Authentication
To get content from Contentful, an app should authenticate with an OAuth bearer token.
You can create API keys using Contentful's web interface. Go to the app, open the space that you want to access (top left corner lists all the spaces), and navigate to the APIs area. Open the API Keys section and create your first token. Done.
Don't forget to also get your Space ID.
For more information, check the Contentful's REST API reference on Authentication.
Your first request
The following code snippet is the most basic one you can use to get some content from Contentful with this SDK:
var contentful = require('contentful')
var client = contentful.createClient({
// This is the space ID. A space is like a project folder in Contentful terms
space: 'developer_bookshelf',
// This is the access token for this space. Normally you get both ID and the token in the Contentful web app
accessToken: '0b7f6x59a0'
})
// This API call will request an entry with the specified ID from the space defined at the top, using a space-specific access token.
client.getEntry('5PeGS2SoZGSa4GuiQsigQu')
.then((entry) => console.log(entry))
You can try and change the above example at Tonic, or if you'd prefer a more Browser oriented example, check out this JSFiddle version of our Product Catalogue demo app.
Using this SDK with the Preview API
This SDK can also be used with the Preview API. In order to do so, you need to use the Preview API Access token, available on the same page where you get the Delivery API token, and specify the host of the preview API, such as:
var client = contentful.createClient({
space: 'developer_bookshelf',
accessToken: 'preview_0b7f6x59a0',
host: 'preview.contentful.com'
})
You can check other options for the client on our reference documentation
Documentation/References
To help you get the most out of this SDK, we've prepared reference documentation, tutorials and other examples that will help you learn and understand how to use this library.
Reference documentation
The Contentful's JS SDK reference documents what objects and methods are exposed by this library, what arguments they expect and what kind of data is returned.
Most methods also have examples which show you how to use them.
You can start by looking at the top level contentful
namespace.
From version 3.0.0 onwards, you can access documentation for a specific version by visiting `https://contentful.github.io/contentful.js/contentful/<VERSION>`
Contentful JavaScript resources
Check the Contentful for JavaScript page for Tutorials, Demo Apps, and more information on other ways of using JavaScript with Contentful
REST API reference
This library is a wrapper around our Contentful Delivery REST API. Some more specific details such as search parameters and pagination are better explained on the REST API reference, and you can also get a better understanding of how the requests look under the hood.
Legacy contentful.js
For versions prior to 3.0.0, you can access documentation at https://github.com/contentful/contentful.js/tree/legacy
Versioning
This project strictly follows Semantic Versioning by use of semantic-release.
This means that new versions are released automatically as fixes, features or breaking changes are released.
You can check the changelog on the releases page.
Migration from contentful.js 2.x and older
contentful.js 3.x was a major rewrite, with some API changes. While the base functionality remains the same, some method names have changed, as well as some internal behaviors.
See the migration guide for more information.
Support
If you have a problem with this library, please file an issue here on Github.
If you have other problems with Contentful not related to this library, you can contact Customer Support.
Contributing
See CONTRIBUTING.md
License
MIT