11 Tweets Jan 31, 2023
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.
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.
Here's the basic syntax of fetching resources using Fetch API.
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.
`fetch()` method also accepts the second init option argument.
You can customize your request using this second parameter.
The options you can pass:
โ€ข 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.

Loading suggestions...