如何从后端执行REST调用

时间:2016-05-11 08:52:55

标签: javascript node.js

我有以下API,当被调用时,将返回结果显示:

app.get('/getAirData', function (req, res) {
  requestApi('http://www.airnowapi.org/aq/observation/zipCode/current/?format=application/json&zipCode=95131&distance=25&API_KEY=1035C2AC-CDB8-4540-97E4-0E8D82BA335A', function (error, response, body) {
    if (!error && response.statusCode == 200) {
      console.log(body);
      res.json(body);
    }
  });
});

结果:

[{"DateObserved":"2016-05-11 ","HourObserved":0,"LocalTimeZone":"PST","ReportingArea":"San Jose","StateCode":"CA","Latitude":37.33,"Longitude":-121.9,"ParameterName":"O3","AQI":25,"Category":{"Number":1,"Name":"Good"}},{"DateObserved":"2016-05-11 ","HourObserved":0,"LocalTimeZone":"PST","ReportingArea":"San Jose","StateCode":"CA","Latitude":37.33,"Longitude":-121.9,"ParameterName":"PM2.5","AQI":37,"Category":{"Number":1,"Name":"Good"}}]

此API在前端触发.. 我想要的是一个对象每30分钟左右运行一次这个代码并将结果存储在一些变量中..

需要调用该函数的对象如下所示。

function SenObj (id) {
  this.Template = id;
  this.Type = "AirFlow";
  this.Req_ID = "Jessi";

}
//object
var user1 = new SenObj('id');

user1如何从后端本身的http://www.airnowapi.org/aq/observation/zipCode/current/?format=application/json&zipCode=95131&distance=25&API_KEY=1035C2AC-CDB8-4540-97E4-0E8D82BA335A'获取日志结果..

REST调用工作正常,但user1如何在后端获得相同的输出

真的很感激一些帮助。

非常感谢 杰施

0 个答案:

没有答案