Skip to content

Instantly share code, notes, and snippets.

@buckyroberts
Created July 3, 2017 06:31
Show Gist options
  • Save buckyroberts/7722bad0d26e357cd8e5c96dd3fa7d9a to your computer and use it in GitHub Desktop.
Save buckyroberts/7722bad0d26e357cd8e5c96dd3fa7d9a to your computer and use it in GitHub Desktop.
import axios from 'axios';
import {normalize} from 'normalizr';
import actionTypes from '../../../config/action-types';
import settings from '../../../config/settings';
import {setNormalized, stringify} from '../../../utils/general';
import {POST} from '../../../utils/normalize';
import {tokenHeader} from '../../../utils/requestHeaders';
export const getPostList = (params = {}) => async dispatch => {
const MODEL = 'POSTS';
try {
const response = await axios.get(`${settings.API_ROOT}/posts${stringify(params)}`, tokenHeader());
const {entities} = normalize(response.data, [POST]);
setNormalized(dispatch, entities);
} catch(error) {
throw error;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment