Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
dwblair committed Jan 3, 2020
1 parent e456a8b commit 513b0d3
Show file tree
Hide file tree
Showing 8 changed files with 1,574 additions and 0 deletions.
2 changes: 2 additions & 0 deletions node4/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
db.sqlite
9 changes: 9 additions & 0 deletions node4/README.md
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.

37 changes: 37 additions & 0 deletions node4/database.js
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

242 changes: 242 additions & 0 deletions node4/express-api-test.postman_collection.json
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": [
""
]
}
}
]
}
Loading

0 comments on commit 513b0d3

Please sign in to comment.