1.2.2 • Published 7 years ago

contentful-response-parser v1.2.2

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

Contentful Response Parser

version MIT License Standard Standard Version Size

This module will parse the Contentful HTTP API response and resolve all nested Asset and Entry links for easier to work with data

Usage

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

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago