Everything you need to know about Fetch API for making API calls. ๐งต
Fetch API provides an interface for fetching resources over the network.
We can say that Fetch API is an upgradation of XMLHttpRequest.
We can say that Fetch API is an upgradation of XMLHttpRequest.
Fetch API returns a Promise whereas XMLHttpRequest deals with callback making it complex as compared to Fetch.
The Fetch method is entirely based on `promises` that can be resolved to the request's response.
In order to fetch resources using Fetch API, we use `fetch()` method.
It takes one mandatory argument which is nothing but the URL to the resources.
It takes one mandatory argument which is nothing but the URL to the resources.
Fetch API always returns a promise which will be captured by the `then()` method.
Doesn't matter whether your request is successful; Fetch API always returns a Promise.
Doesn't matter whether your request is successful; Fetch API always returns a Promise.
`fetch()` method also accepts the second init option argument.
You can customize your request using this second parameter.
You can customize your request using this second parameter.
The options you can pass:
โข method
โข headers
โข body
โข mode
โข credentials
โข method
โข headers
โข body
โข mode
โข credentials
You can also handle rejected promises using Fetch API. They can be captured by the `catch()` method.
With that said, that's pretty much it for this thread.
Make sure to follow @Rapid_API for more excellent content.
Make sure to follow @Rapid_API for more excellent content.
Loading suggestions...