-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,574 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
db.sqlite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
https://developerhowto.com/2018/12/29/build-a-rest-api-with-node-js-and-express-js/ | ||
|
||
https://github.com/fraigo/node-express-rest-api-example | ||
|
||
# node-express-rest-api-example | ||
|
||
A Basic Node.js/Express REST API implementation example. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
var sqlite3 = require('sqlite3').verbose() | ||
var md5 = require('md5') | ||
|
||
const DBSOURCE = "db.sqlite" | ||
|
||
|
||
let db = new sqlite3.Database(DBSOURCE, (err) => { | ||
if (err) { | ||
// Cannot open database | ||
console.error(err.message) | ||
throw err | ||
}else{ | ||
console.log('Connected to the SQlite database.') | ||
console.log('hooray'); | ||
db.run(`CREATE TABLE user ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
dateTime INTEGER, | ||
temperature FLOAT(4,2), | ||
pressure FLOAT(4,2) | ||
)`,(err) => { | ||
if (err) { | ||
// Table already created | ||
console.log("already created"); | ||
}else{ | ||
// Table just created, creating some rows | ||
var insert = 'INSERT INTO user (dateTime,temperature,pressure) VALUES (?,?,?)' | ||
var ts = Math.round((new Date()).getTime() / 1000); | ||
db.run(insert, [ts,23.3,55.2]) | ||
//db.run(insert, [12123124,19.2,23.2]) | ||
} | ||
}) | ||
} | ||
}) | ||
|
||
|
||
module.exports = db | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,242 @@ | ||
{ | ||
"info": { | ||
"_postman_id": "805956e0-e484-49da-8354-2a98f6749e8c", | ||
"name": "Express Basic", | ||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" | ||
}, | ||
"item": [ | ||
{ | ||
"name": "Create", | ||
"request": { | ||
"auth": { | ||
"type": "bearer", | ||
"bearer": [ | ||
{ | ||
"key": "token", | ||
"value": "{{token}}", | ||
"type": "string" | ||
} | ||
] | ||
}, | ||
"method": "POST", | ||
"header": [ | ||
{ | ||
"key": "Content-Type", | ||
"name": "Content-Type", | ||
"value": "application/x-www-form-urlencoded", | ||
"type": "text" | ||
} | ||
], | ||
"body": { | ||
"mode": "urlencoded", | ||
"urlencoded": [ | ||
{ | ||
"key": "name", | ||
"value": "test", | ||
"type": "text" | ||
}, | ||
{ | ||
"key": "email", | ||
"value": "[email protected]", | ||
"type": "text" | ||
}, | ||
{ | ||
"key": "password", | ||
"value": "test123", | ||
"type": "text" | ||
} | ||
] | ||
}, | ||
"url": { | ||
"raw": "http://localhost:8000/api/user/", | ||
"protocol": "http", | ||
"host": [ | ||
"localhost" | ||
], | ||
"port": "8000", | ||
"path": [ | ||
"api", | ||
"user", | ||
"" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "Update", | ||
"request": { | ||
"auth": { | ||
"type": "bearer", | ||
"bearer": [ | ||
{ | ||
"key": "token", | ||
"value": "{{token}}", | ||
"type": "string" | ||
} | ||
] | ||
}, | ||
"method": "PATCH", | ||
"header": [ | ||
{ | ||
"key": "Content-Type", | ||
"name": "Content-Type", | ||
"value": "application/x-www-form-urlencoded", | ||
"type": "text" | ||
} | ||
], | ||
"body": { | ||
"mode": "urlencoded", | ||
"urlencoded": [ | ||
{ | ||
"key": "name", | ||
"value": "Admin", | ||
"type": "text" | ||
} | ||
] | ||
}, | ||
"url": { | ||
"raw": "http://localhost:8000/api/user/1", | ||
"protocol": "http", | ||
"host": [ | ||
"localhost" | ||
], | ||
"port": "8000", | ||
"path": [ | ||
"api", | ||
"user", | ||
"1" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "Get", | ||
"request": { | ||
"auth": { | ||
"type": "bearer", | ||
"bearer": [ | ||
{ | ||
"key": "token", | ||
"value": "{{token}}", | ||
"type": "string" | ||
} | ||
] | ||
}, | ||
"method": "GET", | ||
"header": [], | ||
"body": { | ||
"mode": "raw", | ||
"raw": "" | ||
}, | ||
"url": { | ||
"raw": "http://localhost:8000/api/user/1", | ||
"protocol": "http", | ||
"host": [ | ||
"localhost" | ||
], | ||
"port": "8000", | ||
"path": [ | ||
"api", | ||
"user", | ||
"1" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "List", | ||
"request": { | ||
"auth": { | ||
"type": "bearer", | ||
"bearer": [ | ||
{ | ||
"key": "token", | ||
"value": "{{token}}", | ||
"type": "string" | ||
} | ||
] | ||
}, | ||
"method": "GET", | ||
"header": [], | ||
"body": { | ||
"mode": "raw", | ||
"raw": "" | ||
}, | ||
"url": { | ||
"raw": "http://localhost:8000/api/users/", | ||
"protocol": "http", | ||
"host": [ | ||
"localhost" | ||
], | ||
"port": "8000", | ||
"path": [ | ||
"api", | ||
"users", | ||
"" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "Delete", | ||
"request": { | ||
"auth": { | ||
"type": "bearer", | ||
"bearer": [ | ||
{ | ||
"key": "token", | ||
"value": "{{token}}", | ||
"type": "string" | ||
} | ||
] | ||
}, | ||
"method": "DELETE", | ||
"header": [], | ||
"body": { | ||
"mode": "raw", | ||
"raw": "" | ||
}, | ||
"url": { | ||
"raw": "http://localhost:8000/api/user/26", | ||
"protocol": "http", | ||
"host": [ | ||
"localhost" | ||
], | ||
"port": "8000", | ||
"path": [ | ||
"api", | ||
"user", | ||
"26" | ||
] | ||
} | ||
}, | ||
"response": [] | ||
} | ||
], | ||
"event": [ | ||
{ | ||
"listen": "prerequest", | ||
"script": { | ||
"id": "51c31c8a-4fea-4550-b332-9f7688e26a29", | ||
"type": "text/javascript", | ||
"exec": [ | ||
"" | ||
] | ||
} | ||
}, | ||
{ | ||
"listen": "test", | ||
"script": { | ||
"id": "14a66547-27fa-4147-b4cc-7da84ab1427e", | ||
"type": "text/javascript", | ||
"exec": [ | ||
"" | ||
] | ||
} | ||
} | ||
] | ||
} |
Oops, something went wrong.