Skip to content

Instantly share code, notes, and snippets.

@aray12
Created January 24, 2017 02:59
Show Gist options
  • Save aray12/7f859c5eb04201517f9e3be5491023d8 to your computer and use it in GitHub Desktop.
Save aray12/7f859c5eb04201517f9e3be5491023d8 to your computer and use it in GitHub Desktop.
With redux-api-middelware takes a property called query and appends a query string to the endpoint
import qs from 'querystring';
import { CALL_API } from 'redux-api-middleware';
export default function queryMiddleware() {
return next => action => {
if (action.hasOwnProperty(CALL_API) && action[CALL_API].hasOwnProperty('query')) {
const request = action[CALL_API];
request.endpoint = [
request.endpoint.replace(/\?*/, ''),
qs.stringify(request.query),
].join('?');
delete request.query;
return next({ [CALL_API]: request });
}
return next(action);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment