Created
June 15, 2014 21:02
-
-
Save dalelane/494433bb2d1fa9d3d4c3 to your computer and use it in GitHub Desktop.
Node.js and Express to make a few REST API endpoints (based on sample in http://expressjs.com/4x/api.html )
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
var express = require('express'); | |
var app = express(); | |
console.log("Registering endpoint: /"); | |
app.get('/', function(req, res){ | |
res.send('hello ROOT world'); | |
}); | |
console.log("Registering endpoint: /stubbed"); | |
app.get('/stubbed', function(req, res){ | |
res.send('hello STUBBED'); | |
}); | |
console.log("Registering endpoint: /testing"); | |
app.get('/testing', function(req, res){ | |
res.send('this is a test endpoint'); | |
}); | |
console.log("Registering endpoint: /jsonendpoint"); | |
app.get('/jsonendpoint', function(req, res){ | |
res.json({ | |
"mykey" : "myvalue", | |
"testy" : "something", | |
"exnum" : 123 | |
}); | |
}); | |
app.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment