title: Create a generic function to GET data using fetch in Javascript
body: <p>I am trying to get my hands on vanilla JS.</p>
  
  <p>I came across the fetch API that can be used to make calls to URL and I am wondering if I can make a generic function to be used across my application.</p>
  
  <p>This is is the function I have currently </p>
  
  <pre><code>async function get(url){
        const response = await fetch(url);
        const data = await response.json()
        return data
  }
  </code></pre>
  
  <p>I have worked with Fetch before but in react where I would call the <code>this.setState()</code> function inside the async function. 
  The function above returns a promise and not the actual json data I should get from the URL. I completely understand why it does that.</p>
  
  <p>I want to know if there is a way to make a generic function say function <code>myGet(url)</code> which when called returns the json object retrieved from the GET call and not the promise. 
  Then I can call this function all across my application.</p>
  
  <p>I don't want to write my rest of the code inside the .then() function after I get the response.</p>