Create Read Update Delete(CRUD) API for sqlite database using nodejs - Raspberry Pi GPIO control
$ git clone https://github.com/apvenkat/crud-gpio-sqlite-api
$ cd crud-gpio-sqlite-api
$ npm install
$ node crud.js
The server will be running on port 4300
Once you execute, under your db folder a sqlite database table will be generated automatically. All your CRUD requests will takes place here only.
- Add a new device:
http://localhost:4300/api/
Sending a JSON body:
{
"name": "LED 1",
"description": "an led device",
"pin": 4,
"type": "Input Device",
"value": "true"
}
- Get devices by ID:
http://localhost:4300/api/id/$id
example: http://localhost:4300/api/id/1
- Load all devices:
http://localhost:4300/api/
- Delete a device:
http://localhost:4300/api/delete/$id
example: http://localhost:4300/api/delete/1
ID is the only MANDATORY
- Update a device:
http://localhost:4300/api/id/$id
example: http://localhost:4300/api/id/1
Sending a JSON body: ID is the only MANDATORY
change the json values as needed
{
"id": 1,
"name": "LED 5",
"description": "an led device",
"pin": 18,
"type": "Input Device",
"value": "true"
}
The database will be initially empty and you can add, delete,update or read data as per your requirement
This API can be used for several applications like IoT device Managment, book records, personal check list and so on