import fetch from 'isomorphic-fetch';
import queryString from 'query-string';
import config from '../config';

const handleResponse = (response) => (
  response.ok
    ? response.json()
    : response.json().then((error) => Promise.reject(error))
);

const fireRequest = (method, url, data) => {
  const fullUrl = `${config.apiUrl}${url}`;
  const options = {
    method,
    body: JSON.stringify(data),
    credentials: 'same-origin',
    headers: {
      'Content-Type': 'application/json',
    },
  };
  return fetch(fullUrl, options).then(handleResponse);
};

export default {
  get(url, query) {
    const qs = queryString.stringify(query, { arrayFormat: 'index' });
    return fireRequest('GET', `${url}?${qs}`);
  },

  post(url, data) {
    return fireRequest('POST', url, data);
  },

  put(url, data) {
    return fireRequest('PUT', url, data);
  },

  delete(url) {
    return fireRequest('DELETE', url);
  },
};

@@ -108,148 +108,8 @@
 ';%0A%0A
-const handleResponse = (response) =%3E (%0A  response.ok%0A    ? response.json()%0A    : response.json().then((error) =%3E Promise.reject(error))%0A);%0A%0A
 cons
@@ -123,16 +123,22 @@
 equest =
+ async
  (method
@@ -368,60 +368,146 @@
  %7D;%0A
-  return fetch(fullUrl, options).then(handleResponse
+%0A  const response = await fetch(fullUrl, options);%0A  const json = await response.json();%0A  return response.ok ? json : Promise.reject(json
 );%0A%7D

simplify api.js