문제

I'm making a proxy to the 4chan API. I'm using request.js in Node.js + Express to make the queries to the API and I don't know how exactly implement the "If-modified-since" that the API requires, this is the code:

app.get('/api/boards', function(request, response){
    req({uri:'https://api.4chan.org/boards.json', json: true}, function (error, res, data) {
        if (!error && res.statusCode == 200) {
            response.jsonp(data['boards']);
        }
    });
});

If I make a query to 4chan that already has been done it doesn't answer and the timeout fires.

4chan API rules:

  • Do not make more than one request per second.
  • Thread updating should be set to a minimum of 10 seconds, preferably higher.
  • Use If-Modified-Since when doing your requests.
  • Make API requests using the same protocol as the app. Only use SSL when a user is accessing your app over HTTPS.
  • More to come later...
도움이 되었습니까?

해결책

The request module allows you to pass request headers into the options, so you can do this:

var request = require('request');
var options = {
  uri: 'https://api.4chan.org/boards.json',
  json: true,
  headers: {'If-Modified-Since': 'Sun, 06 Oct 2013 01:16:45 GMT'}
};

request(options, function (error, res, data) {
  // other processing
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top