Created
November 29, 2022 17:32
-
-
Save robertcedwards/d0b659333b84edf95a77193fa32ee79a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myHeaders = new Headers(); | |
var ETagHeaders = new Headers(); | |
myHeaders.append("x-api-key", "INSERT API KEY"); | |
var requestOptions = { | |
method: 'GET', | |
headers: myHeaders, | |
redirect: 'follow' | |
}; | |
var rerequestOptions = { | |
method: 'GET', | |
headers: ETagHeaders, | |
redirect: 'follow' | |
}; | |
fetch("https://api.crew3.xyz/communities/ambire/leaderboard", requestOptions) | |
// Fetch the data with the API key | |
.then(r => ({ | |
etag: r.headers.get('etag'), | |
json: r.json() | |
})) | |
//assign the etag & data to a variable | |
.then(data => { | |
// print the etag & data | |
console.log(data.etag); | |
data.json.then(console.log) | |
// add the etag to the headers + If-None-Match | |
ETagHeaders.append("If-None-Match", data.etag); | |
ETagHeaders.append("x-api-key", "ENTER API KEY"); | |
//fetch with the new headers | |
fetch("https://api.crew3.xyz/communities/ambire/leaderboard", rerequestOptions) | |
.then(r => ({ | |
etag: r.headers.get('etag'), | |
})) | |
.then(data => { | |
// do something with your etag and data | |
console.log(data.etag); | |
// data.json.then(console.log) | |
}) | |
}) | |
.catch(console.error.bind(console)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment