-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api_simple.js
More file actions
64 lines (53 loc) · 1.63 KB
/
test_api_simple.js
File metadata and controls
64 lines (53 loc) · 1.63 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Test API script using built-in http module
const http = require('http');
// Replace this with your actual token from the browser localStorage
const token = process.argv[2] || 'YOUR_TOKEN_HERE';
console.log('Testing profiles API with token:', token.substring(0, 15) + '...');
const options = {
hostname: 'localhost',
port: 5001,
path: '/api/profiles',
method: 'GET',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
};
const req = http.request(options, (res) => {
console.log(`STATUS: ${res.statusCode}`);
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
try {
const parsedData = JSON.parse(data);
console.log('API Response:', JSON.stringify(parsedData, null, 2));
if (parsedData.success) {
console.log(`Found ${parsedData.count} child profiles`);
if (parsedData.data && parsedData.data.length > 0) {
parsedData.data.forEach((profile, index) => {
console.log(`Profile ${index + 1}:`);
console.log(` ID: ${profile.id}`);
console.log(` Name: "${profile.name}"`);
console.log(` Age: ${profile.age}`);
});
}
} else {
console.error('API Error:', parsedData.error);
}
} catch (e) {
console.error('Error parsing response:', e);
console.log('Raw response:', data);
}
});
});
req.on('error', (e) => {
console.error(`Problem with request: ${e.message}`);
});
req.end();
/*
To run this script:
1. Copy your token from the browser's localStorage
2. Run: node test_api_simple.js YOUR_TOKEN
*/