Initial Import, First API Draft

This commit is contained in:
seiichiro 2015-01-28 08:21:10 +01:00
commit a22bc75dbd
4 changed files with 49 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
node_modules

10
package.json Normal file
View file

@ -0,0 +1,10 @@
{
"name": "TempTracker",
"description": "Temperature Database",
"version": "0.0.1",
"private": true,
"dependencies": {
"express": "3.x",
"sqlite3": "3.x"
}
}

18
routes/tempdb.js Normal file
View file

@ -0,0 +1,18 @@
var sqlite3 = require("sqlite3");
exports.getAll = function(req, res) {
res.send([{id: '1', name: 'Wohnzimmer', temp: 20.1}, {id: '2', name: "Schlafzimmer", temp: 18.4}]);
}
exports.getTemp = function(req, res) {
res.send({id: req.params.id, temp: 20.1});
}
exports.addTemp = function(req, res) {
console.log("Adding Temp: " + req.body);
}
exports.updTemp = function(req, res) {
console.log("Updating Temp: " + req.params.id + " Data: " + req.body);
}

20
server.js Normal file
View file

@ -0,0 +1,20 @@
// Main File, configure and start the Server
// Load the modules
var express = require("express");
var tempdb = require("./routes/tempdb.js");
var srv = express();
srv.configure(function() {
srv.use(express.logger('dev'));
srv.use(express.bodyParser());
});
srv.get("/temp", tempdb.getAll);
srv.get("/temp/:id", tempdb.getTemp);
srv.post("/temp", tempdb.addTemp);
srv.put("/temp/:id", tempdb.updTemp);
srv.listen(3000);
console.log("Server started on port 3000.");