helper.js 534 B

123456789101112131415161718192021222324
  1. let host = "http://dyyiaca-m2.wsr.ru/public/api-cafe";
  2. let f = async (url, method="get",token=false, data=[]) => {
  3. let options = {
  4. method: method.toUpperCase(),
  5. headers: {
  6. "Content-type": "application/json"
  7. }
  8. }
  9. if (token) {
  10. options.headers["Authorization"] = `Bearer ${token}`
  11. }
  12. if (["post", "patch"].includes(method)) {
  13. options.body = JSON.stringify(data);
  14. }
  15. return await fetch(`${host}/${url}`, options).then(res=>res.json())
  16. }
  17. export {f, host};