DEV Community

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)