Skip to content

Instantly share code, notes, and snippets.

@robertcedwards
Created November 29, 2022 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertcedwards/d0b659333b84edf95a77193fa32ee79a to your computer and use it in GitHub Desktop.
Save robertcedwards/d0b659333b84edf95a77193fa32ee79a to your computer and use it in GitHub Desktop.
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