title: How to serve file from REST api backend to frontend
body: <p>How do I serve a file from a REST api backend to the frontend?</p>
  <ol>
  <li>User click on download link which programmatically (using ajax) sends a POST request with authentication details is passed to REST api backend.</li>
  <li>Authentication check occurs.</li>
  <li>Some file processing occurs.</li>
  <li>Serve file to frontend as a download.</li>
  </ol>
  <p>Point 5 is where I am having an issue. I can see the binary data is returned from the backend but no download pops up.</p>
  <pre><code>async function apiExportProject(projectID, fileType) {
    
      // Create url.
      let url = new URL(urlBaseAPI + &quot;/project/export&quot;);
    
      // Prepare POST data.
      let formData = new FormData();
      formData.append(&quot;sessionKey&quot;, getSessionKeyCookieValue());
      formData.append(&quot;projectID&quot;, projectID);
      formData.append(&quot;fileType&quot;, fileType);
    
      // Send the POST request.
      await sendPOSTRequest(url, formData);
  }
  
  //GO CODE
      responseWriter.Header().Set(&quot;Content-Disposition&quot;, &quot;attachment; filename=&quot;+strconv.Quote(postFormData.Get(&quot;projectID&quot;)))
      responseWriter.Header().Set(&quot;Content-Type&quot;, &quot;application/octet-stream&quot;)
      http.ServeFile(responseWriter, request, filePath)
  </code></pre>