Created
January 24, 2017 02:59
-
-
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
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 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