-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequest.js
35 lines (30 loc) · 914 Bytes
/
request.js
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
function postChatMessages(chatMessage) {
// The URL of your Flask endpoint
const url = 'https://5000-cs-52c014e8-fcf8-44eb-bf20-a3ccaf8f5fe9.cs-us-east1-pkhd.cloudshell.dev/chat';
// Prepare the headers
const headers = {
'Content-Type': 'application/json',
};
// Prepare the body of the POST request
const body = JSON.stringify(chatMessage);
// Make the POST request
fetch(url, {
method: 'POST',
headers: headers,
body: body
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.text();
})
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
}
// Example usage
const chatMessage = [
{ user: 'Alice', message: 'Hi there!' },
{ user: 'Bob', message: 'Hello!' }
];
postChatMessages(chatMessage);