DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,864 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for Using the Fetch API
hannaA
hannaA

Posted on

Using the Fetch API

Fetching a JSON file across the network and printing it to the console

<div id="posts">...</div>
    <script>
        const API = 'https://';

        const postElement = document.querySelector('#posts');
        let page = 0;

        fetch(`${API}/posts`)
        .then(response => {
            return response.json();
        }) 

        .then(posts => {}
        })
        .catch(error => console.error(error));
    </script>
Enter fullscreen mode Exit fullscreen mode

as a result

Image description

Top comments (0)

Need a better mental model for async/await?

Check out this classic DEV post on the subject.

β­οΈπŸŽ€ JavaScript Visualized: Promises & Async/Await

async await