So I'm trying to retrieve repo data from the Github API for a React app. Due to the rate-limiting on the API, I'm attempting to use conditional requests to check if the data has been modified since the last request, using the If-Modified-Since header.
Here is my test code so far:
const date = new Date().toUTCString();
fetch('https://api.github.com/users/joshlucpoll/repos', {
headers: {'If-Modified-Since': date}
})
.then((res) => {
let headers = res.headers;
console.log(headers)
if (headers.get('status') === "304 Not Modified") {
console.log("Not modified")
}
else {
console.log("modified")
}
});
Every time I run this code I get a 200 OK status, not a 304 Not Modified as expected. The resource can't have updated in the time it's taken to run the code, however, it always outputs "Not modified"...
I can't understand why this isn't working, help would be appreciated!