title: Set default header for every fetch() request
body: <p>Is it possible, using the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch" rel="noreferrer">fetch API</a>, to set default headers for every single request?<br>
  What I want to do is set an <code>Authorization</code> header whenever there is a json web token in the <code>localStorage</code>. My current solution is to set the headers with this function: 
  </p>
  
  <pre><code>export default function setHeaders(headers) {
      if(localStorage.jwt) {
          return {
              ...headers,
              'Authorization': `Bearer ${localStorage.jwt}`
          }
      } else {
          return headers;
      }
  }
  </code></pre>
  
  <p>Setting the headers in a fetch request would then look like this: </p>
  
  <pre><code>return fetch('/someurl', {
          method: 'post',
          body: JSON.stringify(data),
          headers: setHeaders({
              'Content-Type': 'application/json'
          })
      })
  </code></pre>
  
  <p>But there has to be a better way to do this. I'm currently developing a React/Redux/Express app if that is of any help.</p>