Last active
January 4, 2018 15:11
-
-
Save fpersico/4ef864b6cae370eb49f43e3c8a0934c9 to your computer and use it in GitHub Desktop.
Api index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import superagent from 'superagent'; | |
import superagentJsonapify from 'superagent-jsonapify'; | |
superagentJsonapify(superagent); | |
const BASE_URL = 'http://drupal.docker.localhost:8000'; | |
const CONSUMER_ID = 'fd49afa9-81ef-4550-927c-9c7e5da995b7'; | |
const PAGE_SIZE = 10; | |
export const fetchArticles = page => { | |
const pageOffset = PAGE_SIZE * (page - 1); | |
return superagent.get( | |
`${BASE_URL}/jsonapi/node/article?page[offset]=${pageOffset}&page[limit]=${PAGE_SIZE}&sort=-created` | |
); | |
}; | |
export const fetchArticle = uuid => { | |
return superagent | |
.get(`${BASE_URL}/jsonapi/node/article/${uuid}?include=field_image`) | |
.set('X-Consumer-ID', CONSUMER_ID); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment