fetch response page code example
Example 1: get data from api in javascript
const GetData = [];
useEffect(() => {
fetch(API_URL)
.then((res) => res.json())
.then((data) => {
GetModesData.push(...data);
setDataState(GetData.map((d) => d.modeName));
});
}, []);
Example 2: api response
Response
Status code
2xx -->> success
4xx -->> client side error
5xx -->> server side error
Header
meta data about your response
like Content-Type, Date and some other info
Body | Payload
The response we got from the server
and this where we do lots of validation