-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfetchpost.js
More file actions
44 lines (35 loc) · 996 Bytes
/
fetchpost.js
File metadata and controls
44 lines (35 loc) · 996 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
POST
const url = 'https://api.example.com/endpoint'; // Replace with your API endpoint URL
const data = {
name: 'John Doe',
email: 'john.doe@example.com'
}; // Replace with the data you want to send in the POST request
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
};
fetch(url, options)
.then(response => response.json())
.then(data => {
console.log('Response:', data);
// Do something with the response data
})
.catch(error => {
console.error('Error:', error);
// Handle any errors that occurred during the request
});
GET
const url = 'https://api.example.com/endpoint'; // Replace with your API endpoint URL
fetch(url)
.then(response => response.json())
.then(data => {
console.log('Response:', data);
// Do something with the response data
})
.catch(error => {
console.error('Error:', error);
// Handle any errors that occurred during the request
});