import request from '../utils/request'

export function fetch(option) {
  // let client =  new XMLHttpRequest();
  // client.open('POST', 'http://192.168.253.129:8080/showHistogram');
  // client.setRequestHeader('Content-Type', 'application/json');
  // client.send(JSON.stringify(values));
  const { url, body } = option;
  const token = window.localStorage.getItem("token");
  return request(url, {
    method: 'POST',
    headers: {
      token: token,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(body)
  });
  // return request(`http://localhost:8001/api/users?_page=1&_limit=3`);
}

export function remove(id) {
  return request(`/api/users/${id}`, {
    method: 'DELETE',
  });
}

export function patch(id, values) {
  return request(`/api/users/${id}`, {
    method: 'PATCH',
    body: JSON.stringify(values),
  });
}

export function create(values) {
  return request('/api/users', {
    method: 'POST',
    body: JSON.stringify(values),
  });
}
