title: Fetching data with redux actions
body: <p>I am having an issue internally with how to structure my redux actions that fetch data via a rest api.</p>
  
  <p>I am fetching a variety of data like</p>
  
  <ul>
  <li>all posts published</li>
  <li>a singular post </li>
  <li>all current users</li>
  <li>search results</li>
  </ul>
  
  <p>I am wondering if I create an action that fetch's the data from each endpoint or if I create a singular fetch action that fetches the data from a supplied route?</p>
  
  <p>Current Implementation:</p>
  
  <pre><code>function requestPosts(site) {
  return {
      type: REQUEST_POSTS,
      site
  }
  
  function fetchPosts(site) {
  return dispatch =&gt; {
      dispatch(requestPosts(site))
      return fetch(`http://notareallink.com/posts`)
          .then( response =&gt; response.json() )
          .then( json =&gt; dispatch( receivePosts( site, json ) ) )
  }
  
  function requestPost(site) {
  return {
      type: REQUEST_POST,
      site
  }
  
  function fetchPost(site) {
  return dispatch =&gt; {
      dispatch(requestPost(site))
      return fetch(`http://notareallink.com/post/post-id`)
          .then( response =&gt; response.json() )
          .then( json =&gt; dispatch( receivePost( site, json ) ) )
  }
  
  function requestUsers(site) {
  return {
      type: REQUEST_USERS,
      site
  }
  
  function fetchUsers(site) {
  return dispatch =&gt; {
      dispatch(requestUsers(site))
      return fetch(`http://notareallink.com/users`)
          .then( response =&gt; response.json() )
          .then( json =&gt; dispatch( receiveUsers( site, json ) ) )
  }
  </code></pre>
  
  <p>To me this feels like a load of duplicate code basically doing the same thing (Fetching the data from the endpoint).</p>
  
  <p>Is this the correct way to do it or should I be creating a singular action that does the data fetch and pass it the relevant route?</p>
  
  <p>I am sorry if this is not very clear but I am trying to wrap my head around this as I type this out.</p>