Axios Instance

Two Axios instances has been created for this project

  • Private Instance: Named as axios and stored in the path src\lib\axios\index.ts Used to make api calls to protected routes, ie the routes that requires user to be authenticated. This instance will automatically attach the JWT Token in the headers for authentication purpose.

  • Public Instance: Named as axiosPublic and stored in the path src\lib\axios\index.ts Use this if you need to make api calls to a public routes like forgot-password, reset-password, where you dont want to attach the Authorization token and those called api not need that.

How to use Private Insance

Wherever in the services you need to use Private Instance you need to import and use just like you use axios. All the endpoints of MTD will make use of this except some endpoints that does not require Authentication. Consider the following code example:

import axios from "@/lib/axios";
 
const { data } = await axios.get<SelectAssignee>(
  `/accounts/ACCT_10001/members?${stringify({
    keyword,
    fetchSize,
    startIndex,
    sortBy,
  })}`;
 
Notice two things:
 
1. You dont need to prefix the `/xapi/v1` in every request as this is configured in the instance itself.
 
2. You need to pass the type of the response you are expecting back to get the Typescript Autocompletion.
 
#### How to use Public instance
 
Wherever in the services you need to use `Public Instance` you need to import and use just like you use `axios`. Consider the following code example:
 
```javascript
import { axiosPublic } from "@/lib/axios";
 
const { data } = await axios.get<Countries[]>(`/countries`);

How to make calls to any external api that lies the scope of MTD

When you want to make an api call outside the MTD, you can simply use axios directly like the following code. Notice here you will need to specify the full path of the endpoint

import axios from "axios";
 
const { data } =
  (await axios.get) < GithubUser > "https://api.github.com/users";