-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathfatch.js
More file actions
30 lines (20 loc) · 892 Bytes
/
fatch.js
File metadata and controls
30 lines (20 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// AUTHOR: IJAYZZ
// JavaScript Concept: Fetch API
// GITHUB: https://github.com/ijayzz
//FETCH API
//So, fetch is bascially a way to call you API's.
//The Fetch API provides a JavaScript interface for accessing and manipulating parts of the HTTP pipeline, such as requests and responses.
//A fetch function is provided in the global window scope, with the first argument being the URL.
// So an example to use the fetch api can be:
fetch("https://jsonplaceholder.typicode.com/todos/1")
.then((response) => response.json())
.then((json) => console.log(json));
fetch("https://jsonplaceholder.typicode.com/todos/1")
.then((response) => response.json())
.then((json) => console.log(json))
.catch((err) => console.log(err));
if (res.status == 500) {
console.log("Internal server error");
} else if (res.status == 504) {
console.log("504 Gateway Timeout");
}