Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
8 views

Fetch Api

JS popular fetch api , short term powerful notes: Explaining some cool methods : Get, Post, Put, Patch, While handling erroring with chaining technique
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
8 views

Fetch Api

JS popular fetch api , short term powerful notes: Explaining some cool methods : Get, Post, Put, Patch, While handling erroring with chaining technique
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 10
Oo @CODE.CLASH Fetch API In JavaScript a ° Hey Everyone © Javascript is everywhere. Millions of webpages are built on JS. in this Post, you'll learn about the JavaScript Fetch API and how to use it to make asynchronous HTTP requests. Do Like, save and Share This Post If You Found This Helpful. r2) Fetch API The Fetch API is a modern interface that allows you to make HTTP requests to servers from web browsers. * If you have worked with XMLHttpRequest (XHR) object. * Fetch API can perform all the tasks as the XHR object does. + Fetch API is much simpler and cleaner. ¢ It uses the Promise to deliver more flexible features to make requests to servers from the web browsers. e Sending a Request The fetch() method is available in the global scope that instructs the web browsers to send a request to a URL. * The fetch() requires only one parameter which is the URL of the resource that you want to fetch. + When the request completes, the promise will resolve into a Response object. response (rae e The text() method returns a Promise that resolves with the complete contents of the fetched resource. ) response. QO) console. (data) ); * Besides the text() method, the Response object has other methods such as json(), blob(), formData() and arrayBuffer() to handle the respective type of data. oO Reading the Response The fetch() method returns a Promise so you can use the then() and catch() methods to handle it. + If the contents of the response are in the raw, text format, you can use the text() method. 6 @CODE.CLASH In practice, you often use the async/ await with the fetch() method like this: Of response ( data Ba Se console. (data); —> | @CoDE.CLASH } The object provides the and via the and properties. asyne function (omnes let response = await ('/xeadme.txt'); ele) ele (response.status) ; ele) (response. statusText) ; if (response.status 200) { let data = await response. O; oe | have already made posts on async/await and Promises in detail. Go and check out my Javascript Guide. If you have any queries then let me know in the comment box. THANKS FOR YOUR ATTENTION Cope.cLasH —_ fy Imtivaz NANDASANIYA LIKE AND SAVE IT FOR LATER

You might also like