Saturday, April 27, 2019

await fetch in Chrome dev tools console

Here is a simple way to get data from a web URL in Chrome dev tools console.
Since fetch() is an async function that returns a javascript promise, need to use await keyword, that is now supported by Chrome dev tools console.

await fetch('https://jsonplaceholder.typicode.com/posts').then(r => r.json())
and to make result data nicely formatted as a table:

await fetch('https://jsonplaceholder.typicode.com/posts').then(r => r.json()).then(console.table)

No comments: