|
|
|
|
@ -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,8 +48,34 @@ 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
res.json(sensor);
|
|
|
|
|
app.get('/sensor_logger_API/measurements', (req, res) => {
|
|
|
|
|
res.json(measurements);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.listen(PORT, () => {
|
|
|
|
|
|