Commit 828f919706f8729f86c4cc81199075a4db0ecec7
1 parent
37a149e698
Exists in
master
Add routes for crime data api call
Showing 3 changed files with 40 additions and 1 deletions Side-by-side Diff
index.js
View file @
828f919
1 | 1 | var express = require('express'); |
2 | +var crime = require('./routes/crime'); | |
2 | 3 | |
4 | + | |
3 | 5 | var app = express(); |
4 | 6 | |
5 | 7 | app.set('port', (process.env.PORT || 5000)); |
6 | 8 | |
7 | -app.use(express.static(__dirname + '/public')); | |
9 | +app.use(express.static(__dirname + '../public')); | |
8 | 10 | |
9 | 11 | // views is directory for all template files |
10 | 12 | app.set('views', __dirname + '/views'); |
... | ... | @@ -17,6 +19,8 @@ |
17 | 19 | app.get('/landing', function(request, response) { |
18 | 20 | response.render('pages/landing'); |
19 | 21 | }); |
22 | + | |
23 | +app.get('/api', crime.view); | |
20 | 24 | |
21 | 25 | app.listen(app.get('port'), function() { |
22 | 26 | console.log('Node app is running on port', app.get('port')); |
routes/crime.js
View file @
828f919
1 | +var unirest = require('unirest'); | |
2 | + | |
3 | +exports.view = function(req, res){ | |
4 | + | |
5 | + unirest.get("https://yourmapper2.p.mashape.com/datasetlist?format=json&maxlat=40&maxlon=-70&minlat=30&minlon=-90&num=5&sort=location") | |
6 | + .header("X-Mashape-Key", "gj4g6D3zxKmshys7yyf9KNbuywOxp1ueazFjsn6n2fK4sccIGA") | |
7 | + .header("Accept", "application/json") | |
8 | + .end(function (result) { | |
9 | + // console.log(result.status, result.headers, result.body); | |
10 | + | |
11 | + }); | |
12 | + | |
13 | + | |
14 | + | |
15 | + // These code snippets use an open-source library. http://unirest.io/nodejs | |
16 | + unirest.get("https://crimescore.p.mashape.com/crimescore?f=json&id=174&lat=38.08809&lon=-85.679626") | |
17 | + .header("X-Mashape-Key", "gj4g6D3zxKmshys7yyf9KNbuywOxp1ueazFjsn6n2fK4sccIGA") | |
18 | + .header("Accept", "application/json") | |
19 | + .end(function (result) { | |
20 | + res.render('pages/tempcrime', result); | |
21 | + }); | |
22 | + | |
23 | + | |
24 | +}; |
-
mentioned in commit 671e58