Axios is a simple HTTP client with which we create requests in the browser and NodeJS. Its characteristic element is the use of the mechanism of so-called promises, that is, the executed query returns to us its status in the form of either reject or resolve.

 

In practice, queries to the API use "then" and "catch" syntaxes.

import axios from "axios";
axios.get('/users')
  .then(res => {
    console.log(res.data);
  });

 

Interesting facts about how Axios works

Besides the ability to send Get and Post requests, Axios also provides other interesting mechanisms that make it easier to make requests to the API. Below I decided to present a list from the most important ones to the less important ones.

 

Are you looking for a contractor working with Axios ?
logo

Axios config

Working in a project, we have the ability to create many customized Axios configs which we then import into the code. This allows us to create queries that use a different base_url or authorization method.

Axios, zapytania w wyszukiwarce

Axios interceptor

Axios interceptor gives us the ability to catch certain messages or events that occur during API implementation and act accordingly. For example, for any error with authorization, when our authorization token has expired we have the ability to recreate the token and resend the request without the user being aware of the event.

 

Axios and AbortController

As of version 0.22.0, Axios provides the ability to use AbortController, that is, to cancel a query that has been created. This provides a number of possibilities in the form of cancelling a long-running query while moving to another subpage of the application, or when the application logic requires it.

Our offer

Web development

Find out more

Mobile development

Find out more

E-commerce

Find out more

UX/UI Design

Find out more

Outsourcing

Find out more

Related articles

Show all articles