Node npm Unirest gives stale/old data

134 Views Asked by At

I am using Unirest middleware from inside my node js script to make a GET request. However for some reason I am getting stale/old data from the resource being requested.

Even after updating the data, I am getting stale data from the resource. Here's the code :

let unirest = require('unirest');
unirest.get('<resource_url>')
.headers({"cache-control": "no-cache"})
.end(function (response) {
   console.log('body===>',JSON.stringify(response.body));
   console.log('status=====>',response.status);
   console.log('response headers=====>',response.headers);
});

response headers=====> { 'strict-transport-security': 'max-age=15768000; includeSubDomains ', date: 'Fri, 15 Sep 2017 18:58:40 GMT', cached_response: 'true', 'cache-control': 'no-transform, max-age=3600', expires: 'Fri, 15 Sep 2017 12:10:53 GMT', vary: 'Accept,Accept-Encoding', 'content-length': '1383', connection: 'close', 'content-type': 'application/json', 'content-language': 'en-US' }

The same resource gives updated data instantly when tried via Python scipt or CURL.

Note : After some time say 3hrs, the node js script gives updated data.

0

There are 0 best solutions below