Skip to content

Instantly share code, notes, and snippets.

@htsign
Last active October 26, 2016 10:39
Show Gist options
  • Select an option

  • Save htsign/4bce3763c86dfe26aa103a5296d85c9b to your computer and use it in GitHub Desktop.

Select an option

Save htsign/4bce3763c86dfe26aa103a5296d85c9b to your computer and use it in GitHub Desktop.
get all response headers and a parsed JSON result with "Fetch API" on ES2015
(() => {
const promise = fetch("//api.github.com/users/octocat/orgs");
promise.then(res => {
const headers = res.headers;
for (let key of headers.keys()) {
console.log(`${key} : ${headers.get(key)}`);
}
return res.json(); // return JSON object, not serialized string
})
.then(json => console.log(json));
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment