Reader small image

You're reading from  React Application Architecture for Production

Product typeBook
Published inJan 2023
Reading LevelExpert
PublisherPackt
ISBN-139781801070539
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Alan Alickovic
Alan Alickovic
author image
Alan Alickovic

Alan Alickovic is a software developer, mentor and open source enthusiast from Serbia. He has extensive experience in building scalable applications from startups to large organizations. Besides being an individual contributor he has also been leading teams and mentoring other developers. By the time of this writing, he is working as a senior software engineer at Vroom.
Read more about Alan Alickovic

Right arrow

Configuring the API client

For the API client of our application, we will be using Axios, a very popular library for handling HTTP requests. It is supported in both the browser and the server and has an API for creating instances, intercepting requests and responses, canceling requests, and so on.

Let’s start by creating an instance of Axios, which will include some common things we want to be done on every request.

Create the src/lib/api-client.ts file and add the following:

import Axios from 'axios';
import { API_URL } from '@/config/constants';
export const apiClient = Axios.create({
  baseURL: API_URL,
  headers: {
    'Content-Type': 'application/json',
  },
});
apiClient.interceptors.response.use(
  (response) => {
    return response.data;
  },
  (error) => {
    const message =
   ...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
React Application Architecture for Production
Published in: Jan 2023Publisher: PacktISBN-13: 9781801070539

Author (1)

author image
Alan Alickovic

Alan Alickovic is a software developer, mentor and open source enthusiast from Serbia. He has extensive experience in building scalable applications from startups to large organizations. Besides being an individual contributor he has also been leading teams and mentoring other developers. By the time of this writing, he is working as a senior software engineer at Vroom.
Read more about Alan Alickovic