ImAnAutie / storelandUI

UI for storeland
0 stars 0 forks source link

HTTP helper function #11

Open ImAnAutie opened 2 years ago

ImAnAutie commented 2 years ago

So instead of making HTTP calls like

   await keycloak.updateToken(30);
    const channelReq = await fetch(
      `${config("storelandCORE")}/company/${
        Alpine.store("appCompany")._id
      }/channel`,
      {
        method: "GET",
        headers: {
          "Content-Type": "application/json",
          Authorization: `Bearer ${keycloak.token}`,
        },
        body: null,
      }
    );
    console.log("Got response");
    const channelRes = await channelReq.json();

it would more be

const channelRes = await makeRequest(`${config("storelandCORE")}/company/${
        Alpine.store("appCompany")._id
      }/channel`, "GET",null);
ImAnAutie commented 2 years ago

Could possibly also remove the need to provide the storelandCORE URL (EG)

const channelRes = await makeRequest(`company/${
        Alpine.store("appCompany")._id
      }/channel`, "GET",null);
ImAnAutie commented 2 years ago

Made one! makeStorelandRequest(url, httpMethod, body)

Migrating to it now, import from src/storelandAPI.js