tiagopazhs / PetroTrack

0 stars 0 forks source link

Create Real-Time Data Reception Endpoint #2

Closed tiagopazhs closed 2 weeks ago

tiagopazhs commented 2 weeks ago

Description

Develop an API endpoint using Node.js and Express to receive sensor data in JSON format and store it in the database. The endpoint should accept POST requests with the following payload format:

{
  "equipmentId": "EQ-12495",
  "timestamp": "2023-02-15T01:30:00.000-05:00",
  "value": 78.42
}
tiagopazhs commented 2 weeks ago

Test using curl:

➜  src git:(IS-02/create-real-time-reception-endpoint) ✗ curl -X POST http://localhost:3000/sensor-data \
-H 'Content-Type: application/json' \
-d '{
      "equipmentId": "EQ-12495",
      "timestamp": "2023-02-15T01:30:00.000-05:00",
      "value": 78.42
    }'

{"message":"Data received"}%

Server logs:

Received data: {
  equipmentId: 'EQ-12495',
  timestamp: '2023-02-15T01:30:00.000-05:00',
  value: 78.42
}