new post new const

main
Francisco Ferreira 6 days ago
parent 38f84034ca
commit b3c0de914a

@ -2,7 +2,8 @@ const express = require("express");
const app = express();
const PORT = 3030;
app.use(express.json());
const measurements = [ ]; //empty array
const sensors = [
{
id: 'htu21d-01',
@ -47,10 +48,36 @@ app.get('/sensor_logger_API/sensors/:id',(req, res) => {
error: 'sensor not found'
});
}
res.json(sensor);
});
app.post('/sensor_logger_API/measurements', (req, res) => {
//require json structure
//recieve the measurement
const measurement = req.body;
//verify typo of object
//vcalidate submitted fields id
//verify type of object
//validate submitted fields
//store in memory}
measurements.push(measurement);
//show it in terminal
console.log('Recieved:',measurement);
//confirm status and storing
res.status(201).json(measurement);
}
);
app.get('/sensor_logger_API/measurements', (req, res) => {
res.json(measurements);
});
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}`);
});

Loading…
Cancel
Save