import fetch from 'isomorphic-fetch';

const API_BASE = 'https://restcountries.eu/rest/v1';

const baseHeaders = Object.freeze({
  Accept: 'application/json'
});

const jsonHeaders = Object.assign({}, baseHeaders, {
  'Content-Type': 'application/json'
});

function parseResponse(response) {
  if (response.headers.get('Content-Type').indexOf('application/json') === 0) {
    return response.json().then((body) => {
      return [body, response];
    });
  }

  return response.text().then((body) => {
    return [body, response];
  });
}

export function get(path) {
  return fetch(API_BASE + path, {
    method: 'get',
    headers: baseHeaders
  }).then(parseResponse);
}

export function put(path, body) {
  return fetch(API_BASE + path, {
    method: 'put',
    headers: jsonHeaders,
    body: JSON.stringify(body)
  }).then(parseResponse);
}

export function post(path, body) {
  return fetch(API_BASE + path, {
    method: 'post',
    headers: jsonHeaders,
    body: JSON.stringify(body)
  }).then(parseResponse);
}

export function del(path) {
  return fetch(API_BASE + path, {
    method: 'delete',
    headers: baseHeaders
  }).then(parseResponse);
}

export function patch(path, body) {
  return fetch(API_BASE + path, {
    method: 'patch',
    headers: jsonHeaders,
    body: JSON.stringify(body)
  }).then(parseResponse);
}

@@ -28,24 +28,171 @@
 ic-fetch';%0A%0A
+// Here's a mirror of the %60/all%60 response, in case this API ever disappears:%0A// https://gist.github.com/dylanpyle/2795245b57df7a8baa643c08f0680b4c%0A
 const API_BA

Add gist backup link