我想发出一个返回 json 数据的 POST 请求,然后我想获取一些键值,然后创建一个 json 字符串,然后将该 json 字符串放入 url。理想情况下,希望这种情况每 30 秒发生一次。我在这里设置了一些代码https://runkit.com/lukejamison/5d2dfbf99644eb0013c64a56
var GeoJSON = require("geojson");
const stringify = require("json-stringify-pretty-compact");
var apikey = process.env.xapikey;
var options = {
method: 'POST',
url: 'https://app.detrack.com/api/v1/vehicles/view/all.json',
headers: {
'x-api-key': apikey,
}
};
exports.endpoint = function(httpRequest, response) {
if (!apikey){
return response.end('"xapikey" key is missing.');
}
request(options, function (error, httpResponse, body){
try{
var jsonresponse = JSON.parse(body)
var lat1 = jsonresponse.vehicles[0].lat
var lng1 = jsonresponse.vehicles[0].lng
response.end(stringify({ geometry: { type: "Point", coordinates: [lng1, lat1]}, type: "Feature", properties:{}}));
}catch(ex){
response.end(ex.toString());
}
});
}