Async GET Call using Fetch API in JavaScript

Fetch API is replacement for XmlHttpRequest with simple syntax returning Promise object which makes async call chaining simpler. Here examples is showing GET call using fetch, you can use other HTTP verbs as well.
  1. fetch('http://jsonplaceholder.typicode.com/users/5',  
  2. {  
  3.     method: 'get'  
  4. })  
  5. .then(function (pending)  
  6. {  
  7.     return pending.json(); //returning response as json after completion of async call, you can use .text() instead to return response as text    
  8. })  
  9. .then(function (response)  
  10. {  
  11.     console.log(response); //recieved GET response    
  12. })  
  13. .catch(function (error)  
  14. {  
  15.     console.log(error); //Handle any error here    
  16. });