JS Fetch API Tutorial 📜
fetch. Today, we'll be discussing how to use
fetch for AJAX/HTTP requests.
The options argument should be an object/JSON data-type. The reqLink is where you put your request link. The reqLink should be a string.
When you use the fetch function what should be returned is a JS promise.
This is what a promise is: developer.mozilla.org
(JSONplaceholder is an arbituary fake REST API that I chose.) You can check them out here
I'm going to be using an arrow function in these examples which are another way to declare functions
For more information on arrow functions go here
GET request example 📜:
POST request example 📜:
body property is used to insert data through the
Helpful Tips 😁:
- To make a
GETrequest, you don't need anything in the options argument.
- To handle your JS
promisesin a cleaner way, use an asynchronous function
Thanks for reading this far👍
Please consider upvoting this post, it really helps me out 😉
Feel free to give me any suggestions😄