title: Better ways to handle REST API call in Redux
body: <p>In my app, I need to call several REST API endpoints:</p>
  
  <pre class="lang-javascript prettyprint-override"><code>// The UI Class
  class LoginForm extends Component {
      handleSubmit(){
          store.dispatch(login(username, password));
      }
  }
  
  // An action
  function login(username, password){
      return dispatch =&gt; {
          fetch(LOGIN_API, {...})
          .then(response =&gt; {
              if (response.status &gt;= 200 &amp;&amp; response.status &lt; 300){
                  // success
              } else {
                  // fail
              }
          })
      }
  }
  </code></pre>
  
  <p>The gist is above and easy to understand. User triggers an action, an ajax call to the corresponding endpoint is made.</p>
  
  <p>As I am adding more and more API endpoints, I end up with a bunch of functions similar to the skeleton of the <code>login</code> function above.</p>
  
  <p>How should I structure my code in such a way that I don't repeat myself with duplicate ajax functions?</p>
  
  <p>Thanks!</p>