CONSUMING API’S USING FETCH AND AXIOS

CONSUMING API’S USING FETCH AND AXIOS

API.jpg

WHAT IS AN API?

An application programming interface (API) is a computing interface which defines interactions between multiple software. It defines the kinds of calls or request that can be made, how to make them, the data formats that should be used. It is also a set of functions and procedures allowing the creation of applications that access the features or data of and operating system, application or other services.

HOW TO USE THE FETCH API

In a very simple manner, all you really do is call fetch with the URL you wand by default the fetch API uses the GET method, so a call would be like this :-

fetch('http://example.com/movies.json')
  .then(response => response.json())
  .then(data => console.log(data));

HOW TO USE AXIOS

Firstly you install axios

Using yarn

$ yarn add axios

Using npm

npm install axios

Using cdn

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
axios({
  url: 'https://dog.ceo/api/breeds/list/all',
  method: 'get'
})
  console.log(response);