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
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.