*/
// @flow
import { stringify } from 'querystring';
+import { omitBy, isNil } from 'lodash';
import { getCookie } from './cookies';
type Response = {
return value ? { [getCSRFTokenName()]: value } : {};
}
+export function omitNil(obj: Object): Object {
+ return omitBy(obj, isNil);
+}
+
/**
* Default options for any request
*/
if (this.data) {
if (this.data instanceof FormData) {
options.body = this.data;
- } else if (options.method === 'GET') {
- url += '?' + stringify(this.data);
} else {
- customHeaders['Content-Type'] = 'application/x-www-form-urlencoded';
- // $FlowFixMe complains that `data` is nullable
- options.body = stringify(this.data);
+ const strData = stringify(omitNil(this.data));
+ if (options.method === 'GET') {
+ url += '?' + strData;
+ } else {
+ customHeaders['Content-Type'] = 'application/x-www-form-urlencoded';
+ options.body = strData;
+ }
}
}