function request(url, method, body) {
  return fetch(`${BASE_URL}/${url}`, {
    headers: {
      'Content-Type': 'application/json',
    },
    method,
    body: body ? JSON.stringify(body) : undefined,
  }).then((res) => {
    if (res.json) {
      return res.json()
    }
    return res
  })
}

export default request
