api(
    path,
    method = "GET",
    body = null,
    requiresAuth = false,
    credentials = null
  ) {
    const url = config.apiBaseUrl + path; //Link referencing config
    const options = {
      method,
      headers: {
        "Content-Type": "application/json; charset=utf-8"
      }
    };

    if (body !== null) {
      options.body = JSON.stringify(body);
    }
    if (requiresAuth) {
      const encodedCredentials = btoa(
        `${credentials.username}:${credentials.password}`
      );
      options.headers["Authorization"] = `Basic ${encodedCredentials}`;
    }
    return fetch(url, options);
  }
//Class uses fetch for functions to use API
Class uses fetch for functions to use API
Class uses fetch for functions to use API
api(
    path,
    method = "GET",
    body = null,
    requiresAuth = false,
    credentials = null
  ) {
    const url = config.apiBaseUrl + path; 
    const options = {
      method,
      headers: {
        "Content-Type": "application/json; charset=utf-8"
      }
    };
    if (body !== null) {
      options.body = JSON.stringify(body);
    }
    if (requiresAuth) {
      const encodedCredentials = btoa(
        `${credentials.username}:${credentials.password}`
      );
      options.headers["Authorization"] = `Basic ${encodedCredentials}`;
    }
    return fetch(url, options);
  }
api ( path , method = "GET" , body = null , requiresAuth = false , credentials = null ) { const url = config . apiBaseUrl + path ; const options = { method , headers : { "Content-Type" : "application/json; charset=utf-8" } } ; if ( body !== null ) { options . body = JSON . stringify ( body ) ; } if ( requiresAuth ) { const encodedCredentials = btoa ( ` ${ credentials . username } ${ credentials . password } ` ) ; options . headers [ "Authorization" ] = ` ${ encodedCredentials } ` ; } return fetch ( url , options ) ; }
Class uses fetch for functions to use API
Class uses fetch for functions to use API
//Link referencing config