Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danhayden/contentful-response-parser
Parse Contentful HTTP API response and resolve all nested Asset and Entry links
https://github.com/danhayden/contentful-response-parser
contentful
Last synced: about 2 months ago
JSON representation
Parse Contentful HTTP API response and resolve all nested Asset and Entry links
- Host: GitHub
- URL: https://github.com/danhayden/contentful-response-parser
- Owner: danhayden
- License: mit
- Created: 2017-03-09T12:06:13.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-04-12T12:33:40.000Z (almost 6 years ago)
- Last Synced: 2024-11-25T08:40:59.408Z (2 months ago)
- Topics: contentful
- Language: JavaScript
- Homepage:
- Size: 57.6 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Contentful Response Parser
[![version][version]](http://npm.im/contentful-response-parser)
[![MIT License][MIT License]](http://opensource.org/licenses/MIT)
[![Standard][Standard]](http://standardjs.com)
[![Standard Version][Standard Version]](https://github.com/conventional-changelog/standard-version)
[![Size][Size]](https://unpkg.com/contentful-response-parser)This module will parse the Contentful HTTP API response and resolve all nested Asset and Entry links for easier to work with data
## Usage
```js
import axios from 'axios'
import { generateItemObject, generateItemObjectArray } from 'contentful-response-parser'const spaceId = 'xxxxxx'
const accessToken = 'xxxxxx'const contenfulAPI = axios.create({
method: 'get',
baseURL: `https://cdn.contentful.com/spaces/${spaceId}/entries`,
headers: { Authorization: `Bearer ${accessToken}` }
})export const getAllBlogPosts = () => {
const params = { content_type: 'blogPost', include: 10 }
return contenfulAPI.get('/', {params})
.then(response => response.data)
.then(generateItemObjectArray)
}export const getBlogPost = (postSlug) => {
const params = { content_type: 'blogPost', include: 10, 'fields.slug': postSlug }
return contenfulAPI.get('/', {params})
.then(response => response.data)
.then(generateItemObject)
}
```### Limitations
Currently this library does not support deep nested entries (PRs welcome!)
### License
MIT
[version]: https://img.shields.io/npm/v/contentful-response-parser.svg
[MIT License]: https://img.shields.io/npm/l/contentful-response-parser.svg
[Standard]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg
[Standard Version]: https://img.shields.io/badge/release-standard%20version-brightgreen.svg
[Size]: https://badges.herokuapp.com/size/npm/contentful-response-parser?gzip=true&label=gzipped