newenthusiast newenthusiast - 2 months ago 12
Javascript Question

How to send query from nodejs server to open data server?

I'm working with open data: https://data.sfgov.org/Economy-and-Community/Mobile-Food-Facility-Permit/rqzj-sfat

The open data site allows to query the data, and example query is below: https://soda.demo.socrata.com/resource/4tka-6guv.json?$where=magnitude > 3.0
However, this, I imagine is URL querying. If I had to get the same object on my nodejs server, how would I format the query to receive the json objects on the node server?

Are there any security threats or exposing threats to querying for data this way?

Answer

Probably the easiest way to do this is via request package. You could do something like the following:

var request = require('request');

request('https://soda.demo.socrata.com/resource/4tka-6guv.json?$where=magnitude%3E3.0', function (err, res, body) {
  if (err) {
    //handle error
  } else {
    console.log(body); // and do stuff with your results
  }
});

If you run this, you'll see a print out of your result array. There aren't really any security threats with this. Your just doing a GET request from an open data source. Pretty standard stuff. Same kind of transactions happen everyday all over the web.

Comments