我正在使用4chan API.代理我在Node.js + Express中使用request.js来对API进行查询而我不知道如何实现“If” -modified-自“API需要,这是代码:
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']);
}
});
});
如果我查询已经完成的4chan,它就不会回答,并且会超时。
4chan API规则:
- 每秒不要多于一个请求。
- 线程更新应设置为最少10秒,最好更高。
- 使用If-Modified-执行请求时。
- 使用与应用程序相同的协议发出API请求。仅当用户通过HTTPS访问您的应用时才使用SSL。
- 以后会有更多......
答案 0 :(得分:4)
请求模块允许您将请求标头传递到选项中,因此您可以执行以下操作:
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
});