export default {
  get({ name }) {
    let uri = '/api/projects?';
    if (name) {
      uri += `email=${name}`;
    }
    return fetch(uri)
      .then(response => response.json());
  },

  getById(id) {
    const uri = `/api/projects/${id}`;
    return fetch(uri)
      .then(response => response.json());
  },

  create({ name }) {
    return fetch('/api/projects', {
      method: 'POST',
      body: JSON.stringify({ name }),
      headers: {
        'content-type': 'application/json',
      },
    })
      .then(response => response.json());
  },

  update(id, { name }) {
    return fetch(`/api/projects/${id}`, {
      method: 'PUT',
      body: JSON.stringify({ name }),
      headers: {
        'content-type': 'application/json',
      },
    })
      .then(response => response.json());
  },

  delete(id) {
    return fetch(`/api/projects/${id}`, {
      method: 'DELETE',
    });
  },
};


export default {
  get({ name }) {
    let uri = '/api/projects?';
    if (name) {
      uri += `email=${name}`;
    }
    return fetch(uri, { credentials: 'include' })
      .then(response => response.json());
  },

  getById(id) {
    const uri = `/api/projects/${id}`;
    return fetch(uri, { credentials: 'include' })
      .then(response => response.json());
  },

  create({ name }) {
    return fetch('/api/projects', {
      method: 'POST',
      body: JSON.stringify({ name }),
      headers: {
        'content-type': 'application/json',
      },
      credentials: 'include',
    })
      .then(response => response.json());
  },

  update(id, { name }) {
    return fetch(`/api/projects/${id}`, {
      method: 'PUT',
      body: JSON.stringify({ name }),
      headers: {
        'content-type': 'application/json',
      },
      credentials: 'include',
    })
      .then(response => response.json());
  },

  delete(id) {
    return fetch(`/api/projects/${id}`, {
      method: 'DELETE',
      credentials: 'include',
    });
  },
};


Send credentials with request