How to fetch data from an API using fetch() method in React Js
- Get link
- X
- Other Apps
How to fetch data from an API using fetch() method in React Js?
Now a day, we can't imagine web application without API so one of the basic requirement of any web application is to communicate with servers through HTTP protocol. This can be easily done using Fetch and Axios.
In this post, we are mainly focusing on Fetch. The Fetch API provides a fetch() method defined on the window object. The fetch method has one mandatory argument i.e., URL of the resource to be fetched. This method returns promise object that can be used to retrieve response of the request.
There are following limitations of Fetch API:
a) Fetch does not allows cancelling request and request timeout.
b) Fetch does not provide a way to intercept HTTP requests.
c) Fetch has no url in request object.
d) No installation is required.
e) Fetch does not have XSRF protection.
f) Fetch uses the body property.
g) Fetch is a two step process when handling JSON data, first - to make actual request. second - to call json() method on the response.
Fetch API React Js |
Sample Code:
A) index.js
B) App.js
C) Users.js
D) style.css
Happy Learning!! Happy Coding!!
- Get link
- X
- Other Apps
Comments
New comments are not allowed.
Mast re
ReplyDelete