-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-api.js
More file actions
33 lines (28 loc) · 716 Bytes
/
Copy pathtest-api.js
File metadata and controls
33 lines (28 loc) · 716 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
const http = require('http');
const data = JSON.stringify({
participantId: "player999",
username: "madhav_the_goat",
eventType: "quiz",
year: 1
});
const options = {
hostname: 'localhost',
port: 3000,
path: '/api/start-quiz',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length
}
};
const req = http.request(options, (res) => {
let responseData = '';
res.on('data', (chunk) => { responseData += chunk; });
res.on('end', () => {
console.log(`STATUS: ${res.statusCode}`);
console.log(`BODY: ${responseData}`);
});
});
req.on('error', (e) => { console.error(`problem with request: ${e.message}`); });
req.write(data);
req.end();