-
Notifications
You must be signed in to change notification settings - Fork 0
/
etags.js
18 lines (15 loc) · 952 Bytes
/
etags.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import {ESIRequest} from "../index.js";
let ESI = new ESIRequest();
(async () => {
// Make a request to an endpoint.
let first = await ESI.request("/v1/universe/races/");
// ESI should respond with a 200 status code.
console.log(first.headers[":status"]);
// Make a second request to the same endpoint, this time passing the response from the first request in the options object.
// The library will use the ETag from the previous response to make a conditional request.
let second = await ESI.request("/v1/universe/races/", {previous_response: first});
// Being made immediately after the first request, the ETags should match, and ESI should respond with a 304 status code.
console.log(second.headers[":status"]);
// The library will reuse the previous response; both responses will have the same data object.
return second.data === first.data;
})().then(console.log, console.error).finally(ESI.close);