35 lines
684 B
JavaScript
35 lines
684 B
JavaScript
const http = require('http');
|
|
|
|
const data = JSON.stringify({
|
|
userId: "default_user",
|
|
date: "2026-06-09",
|
|
meal: {
|
|
id: "test1",
|
|
name: "Apple",
|
|
time: "10:00",
|
|
calories: 100,
|
|
protein: 1,
|
|
fat: 0,
|
|
carbs: 25
|
|
}
|
|
});
|
|
|
|
const req = http.request({
|
|
hostname: 'localhost',
|
|
port: 3131,
|
|
path: '/api/logs/meal',
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Content-Length': Buffer.byteLength(data)
|
|
}
|
|
}, (res) => {
|
|
let body = '';
|
|
res.on('data', chunk => body += chunk);
|
|
res.on('end', () => console.log('Response:', res.statusCode, body));
|
|
});
|
|
|
|
req.on('error', e => console.error('Error:', e));
|
|
req.write(data);
|
|
req.end();
|