title: AngularJS Change api request from php to JSON
body: <p>Hi I've got this app which can connect to an API.</p>
  
  <p>Only problem is it can only <code>get</code> API requests from an <code>PHP</code> file.</p>
  
  <p>I want to change the code so that it wil accept <code>.json</code> API files</p>
  
  <p><strong>Factory</strong></p>
  
  <pre><code>factory.readProducts = function(){
      return $http({
          method: 'GET',
          url: 'https://jsonplaceholder.typicode.com/todos'
      });
      console.log(factory.readProducts)
  
  };
  </code></pre>
  
  <p>Currently my <code>GET</code> method should be presumably be changed to <code>fetch</code> </p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>$scope.readProducts = function(){
  
      // use products factory
      productsFactory.readProducts().then(function successCallback(response){
          $scope.todos = response.data.records;
           console.log($scope.products)
      }, function errorCallback(response){
          $scope.showToast("Unable to read record.");
      });
  
  }
  </code></pre>
  
  <p><strong>JSON method</strong></p>
  
  <pre><code>    fetch('https://jsonplaceholder.typicode.com/todos/1')
    .then(response =&gt; response.json())
    .then(json =&gt; console.log(json))
  </code></pre>
  
  <p>according to <a href="https://jsonplaceholder.typicode.com/" rel="nofollow noreferrer">JSONPlaceholder</a> it's the basic way to acces an JSON API</p>