Use fetch to send get request with data object
<p>I'm using Fetch (<a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API" rel="nofollow">Fetch API</a>) in a project and I would like to, for consistence purposes, create a function that receives all the parameters such as method, url and data and creates the correct request, depending if it's a GET or a POST request. </p>

<p>Is it possible, using Fetch, to send a data object that for the GET request, converts data into and string with the parameters and if it is a POST request, it just sends the data object in the body?</p>

<p>It would look like this:</p>

<pre><code>fetch ('/test', {
        method: 'GET',
        data: {
           test: 'test'
        }
});
</code></pre>

<p>This doubt was inspired by this jQuery ajax behaviour:</p>

<pre><code>$.ajax({
   url: '/test',
   method: 'GET',
   data: {
      test: 'test'
   }
});
</code></pre>

<p>This would produce this request:</p>

<pre><code>'/test/?test=test'
</code></pre>