title: Calling multiple WEB API calls with a Javascript Promise
body: <p>I am trying to wrap my head around Javascript Promises and am confused on where I need to put what. </p>
  
  <p>The scenario is the following. I three JavaScript methods that each call out to a WEB API to save some data. For simplicity sake, I will call them SaveA(), SaveB() and SaveC(). I want them to fire SaveA() first and then have SaveB() fire after SaveA() has finished processing. Then the same scenario for SaveB() and SaveC(). </p>
  
  <p>The WEB API calls in the Save() methods return a null value when finished. I think this may be part of my confusion. These can be changed to return something else though if need be. The WEB API is written in C#. Below is a simplified version of what one of the WEB API methods look like. </p>
  
  <pre><code>//WEB API Signature
  public ActionResult InsertSomething(SomeObjectModel model) { 
      Insert(model);
      return null;
  }
  </code></pre>
  
  <p>Where am I supposed to put my SaveA call? Should it be in a Promise like below? </p>
  
  <pre><code>function SaveAPromise() {
  return new Promise(function (fulfill, reject) {
      try {
          SaveA();
      }
      catch (err) {
          reject(err);
      }
      fulfill("success");
  });
  </code></pre>
  
  <p>}</p>
  
  <p>If so, what do I do with the fulfill? Do I need to turn it into a function to call SaveB()? </p>
  
  <p>Other examples I have seen online have shown stringing together calls using the then part. So does that mean I need to do something like this? If so, then what is the role of the fulfill method in SaveAPromise()? </p>
  
  <pre><code>var promise = SaveAPromise();
  promise.then(SaveB());
  promise.then(SaveC()); 
  </code></pre>
  
  <p>Thanks in advance for any help or clarification you can provide. </p>