Skip to content

Commit f16c49b

Browse files
committed
Example of sending/recieving data via HTTP POST.
0 parents  commit f16c49b

File tree

8 files changed

+26362
-0
lines changed

8 files changed

+26362
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
http-post/receiver/node_modules/
2+
http-post/sender/node_modules/

http-post/receiver/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"use strict";
2+
3+
const express = require('express');
4+
const app = express();
5+
const bodyParser = require('body-parser')
6+
7+
app.use(bodyParser.json());
8+
9+
app.post('/submit-data', (req, res) => {
10+
console.log(req.body);
11+
res.sendStatus(200);
12+
});
13+
14+
app.listen(3000, () => console.log('Example app listening on port 3000!'))

http-post/receiver/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "test-data-receiver",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "MIT",
12+
"dependencies": {
13+
"body-parser": "1.18.2",
14+
"express": "4.16.3"
15+
}
16+
}

http-post/sender/data/ayr-aq-2014.csv

Lines changed: 8761 additions & 0 deletions
Large diffs are not rendered by default.

http-post/sender/data/brisbanecbd-aq-2014.csv

Lines changed: 8761 additions & 0 deletions
Large diffs are not rendered by default.

http-post/sender/data/woolloongabba-aq-2014.csv

Lines changed: 8761 additions & 0 deletions
Large diffs are not rendered by default.

http-post/sender/index.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"use strict";
2+
3+
const fs = require('fs');
4+
const request = require('request-promise');
5+
const papa = require('papaparse');
6+
7+
//
8+
// Load example data.
9+
//
10+
const location = "brisbanecbd";
11+
const parsed = papa.parse(fs.readFileSync("./data/brisbanecbd-aq-2014.csv", "utf8"), { dynamicTyping: true, header: true });
12+
const data = parsed.data;
13+
14+
let curIndex = 0;
15+
16+
setInterval(() => { // Every second send a chunk of data to the server.
17+
18+
const postData = Object.assign({}, data[curIndex]);
19+
curIndex += 1;
20+
21+
postData.Location = location; // Tag the data with a location so that we can differentuate our data sources.
22+
23+
request.post({
24+
method: "POST",
25+
uri: "http://localhost:3000/submit-data",
26+
body: postData,
27+
json: true
28+
});
29+
30+
}, 1000);

http-post/sender/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "mock-data-generator",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "MIT",
12+
"dependencies": {
13+
"papaparse": "4.3.7",
14+
"request": "2.85.0",
15+
"request-promise": "4.2.2"
16+
}
17+
}

0 commit comments

Comments
 (0)