- Python
- Django + SQLite
- Django REST Framework
- Create
virtualenv
usingrequirements.txt
- Run
python manage.py runserver
in commandline. - By default, server runs on port
5000
.
-
An IoT device with properties:
uid
: unique id of devicename
: name of device
-
A device measures humidity and temperature:
HumidityReading
: one-to-manyTemperatureReading
: one-to-many
device
: owner devicehumidity
: readingtimestamp
: timestamp when reading was stored in db
device
: owner devicetemperature
: readingtimestamp
: timestamp when reading was stored in db
- Endpoint:
POST /api/devices/
- Content-Type:
application/json
- Request Payload
uid
name
- Endpoint:
DELETE /api/devices/{device-uid}
device-uid
: uid of device to be deleted
- Endpoint:
GET /api/devices/{device-uid}
device-uid
: uid of device
- Endpoint:
GET /api/devices/
- Response:
json
-
Endpoint:
GET /api/devices/{device-uid}/readings/{parameter}/?start_on=yyyy-mmddTHH:MM:SS&end_on=yyyy-mm-ddTHH:MM:SS
device-uid
: uid of deviceparameter
: temperature or humiditystart_on
andend_on
: query parameters which are compulsary and should be used to filter the result to only include data betweenstart_on
andend_on
.yyyy-mm-ddTHH:MM:SS
: year-monthdateThour:minute:second
-
Response:
json
App can be improved on following:
- Payload cleaning.
- Date range matching using timezones.