title: How to use fetch to post with content-type of application/json
body: <p>I have a react application that does a fetch call to an API as follows:</p>
  
  <pre><code> postForm(state) {
      var formData = state.formData;
      return fetch('http://localhost:3000/api/V0.1/formSubmit', {method: 'POST', headers: {"Content-Type": "application/json"}, body: JSON.stringify(formData)})
      .then((response) =&gt; response.json())
      .then((responseJson) =&gt; {
        console.log(responseJson);
        return null;
      })
      .catch((error) =&gt; {
        console.error(error);
      });
    }
  </code></pre>
  
  <p>however, it gets blocked by CORS as the spec states that application/json is non-standard content type.</p>
  
  <p>However, I'm not sure how I can modify my fetch call to perform the required pre-flight request to get it to allow application/json.</p>
  
  <p>The API call is:</p>
  
  <pre><code>app.post("/api/v0.1/formSubmit", function(req, res) {
    res.setHeader('Access-Control-Allow-Origin', 'http://localhost:8080');
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
    res.setHeader('Access-Control-Allow-Headers', '*');
    var formData=req.body;
    console.log(formData);
    res.status(200).json(formData);
  });
  </code></pre>