-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetchAPI.js
More file actions
44 lines (31 loc) · 856 Bytes
/
fetchAPI.js
File metadata and controls
44 lines (31 loc) · 856 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
fetch("IndiaData.json")
.then((response) => response.json())
.then((data) => {
console.log(data);
});
// .catch((err) => console.log("Error occured"));
// var data = JSON.parse("./IndiaData");
async function logMovies() {
const response = await fetch("https://reqres.in/api/users/2");
const users = await response.json();
console.log(users);
}
logMovies();
//uplolading example
async function postJSON(data) {
try {
const response = await fetch("https://example.com/profile", {
method: "POST", // or 'PUT'
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});
const result = await response.json();
console.log("Success:", result);
} catch (error) {
console.error("Error:", error);
}
}
const data = { username: "example" };
postJSON(data);