Fetch API

Fetch API — Introduction To Promised-based Data Fetching In Plain JavaScript

Suboor Khan
Suboor Khan

Suboor Khan

Software Engineer


Making server requests in JavaScript-based application is a common task. There are different ways of solving that task. Back in the day developers used the XMLHttpRequest (XHR) objects to interact with servers. For the first time it has been possible to retrieve data from a URL without having to do a full page refresh. This was one of the prerequisites to enable a web page to update just parts of the page without needed to do a full refresh.

However, using XMLHttpRequest has never felt very natural to JavaScript developers and has lead to code which is hard to read and understand. External libraries like jQuery or Axios have been trying to solve that problem and have provide better and cleaner server request APIs.

With the release of the Fetch API JavaScript has now build-in a much cleaner promised-based API which can be used to perform server request in an easy way without needing to use third-party libraries.

This tutorial is for all of you who have not worked with the Fetch API yet. In the following steps we’re going to cover the Fetch API basics and learn to perform HTTP GET and POST requests with that API by implementing practical examples.



    
fetch('https://jsonplaceholder.typicode.com/todos/1')
  .then(response => response.json())
  .then(json => cons.log(json))
  

https://sendgb.com/pbh85CsI4xg
https://sendgb.com/kclHACLZ4X3
https://sendgb.com/swjNrC0vXDe
https://sendgb.com/RDEPFCZNs4p
https://sendgb.com/eYHaIyXBRbj
https://sendgb.com/oXkcPusYzFQ
HomeNews feedsWorkSessionsContact