title: How to build a JS interface for an API
body: <p>I'm building an API interface in JS ES6 to allow me to use the CRUD rule in a better way and more efficient. My issue I'm not finding a way to make it work. 
  I created my interface to accept some params and based on which method like GET or POST something should happen and I should see a specific result of the request.</p>
  
  <p>I created an external <code>getProducts()</code> function but is ignored by the system I don't have errors and nothing happen is dead. </p>
  
  <p>What I did in my fetch data interface as follow:</p>
  
  <pre><code>const api = "https://api";
  
  const username = "username";
  const password = "password";
  
  const token = btoa(username + ":" + password);
  
  window.request = async (url, params, method = "GET") =&gt; {
      const options = {
          method,
          headers: {
              "Content-Type": "application/json",
              Authorization: "Basic " + token
          }
      };
  
      if (params) {
          if (method === "GET") {
              url += "?" + objectToQueryString(params);
          } else {
              options.body = JSON.stringify(params);
          }
      }
  
      const response = await fetch(api + url, options);
  
      if (response.status !== 200) {
          return generateErrorResponse(
              "The server responded with an unexpected status."
          );
      }
  
      const result = await response.json();
  
      return result;
  };
  
  objectToQueryString = obj =&gt; {
      return Object.keys(obj)
          .map(key =&gt; key + "=" + obj[key])
          .join("&amp;");
  };
  
  generateErrorResponse = message =&gt; {
      return {
          status: "error",
          message
      };
  };
  
  const Fetch  = () =&gt; {
  
      get = (url, params) =&gt; {
          return request(url, params);
      };
  
      create = (url, params) =&gt; {
          return request(url, params, "POST");
      };
  
      update = (url, params) =&gt; {
          return request(url, params, "PUT");
      };
  
      remove = (url, params) =&gt; {
          return request(url, params, "DELETE");
      };
  };
  </code></pre>
  
  <p>And the function which should get the data:</p>
  
  <pre><code>getProducts = async () =&gt; {
      const products = await Fetch.get("/product");
  };
  </code></pre>
  
  <p>I have trouble understanding what wrong and what should I do to make it run.</p>