Using the Fetch API to get a information on dogs from the Dog API.
- JavaScript
- Dog API
- Download zip file and install
- Open
index.html
in a browser
- The Fetch API is native to the browser
- Using the Fetch API is simpler than using AJAX, XHR or JQuery
- Asynchronous means to update a webpage with information from the server without doing a complete re-page load.
- Fetch API uses JavaScript Promises to handle the results returned from the server.
- Asynchronous JavaScript And XML (AJAX) uses XML Http Request (XHR) object to request data from a web server.
- Fetch method,
fetch('myapi.com/endpoint)
fetch('https://dog.ceo/api/breeds/image/random')
- Get the data with fetch(), then convert it to a json file, then log the message endpoint to the console.
fetch('https://dog.ceo/api/breeds/image/random')
.then(response => response.json())
.then(data => console.log(data.message))