DEV Community

Kavya S
Kavya S

Posted on

Fetch,Axios in JavaScript

What is Fetch?

Fetch is a tool in Javascript that allows website to communicate to a server to get or send information

Why Fetch?

When you shop online,fetch retrieves product details or sends your order to server

Example

<script>
fetch("https://fakestoreapi.com/products")
.then ((res) => res.json())
.then (jsonresponse) => console.log(jsonresponse))
.catch ((rej) => rej.json())
</script>
Enter fullscreen mode Exit fullscreen mode

What is Axios?

  • Axios is an external library
  • Axios is a promise-based HTTP Client for node.js and the browser

Example

axios.get("https://fakestoreapi.com/products")
.then (res => {
console.log(res);
})
.catch (err => {
console.error(err);
})
Enter fullscreen mode Exit fullscreen mode

Top comments (0)