# Axios API Calls

## Mock Calls

Mantis uses fack/mock data to render some pages and actions. Mocking has been achieved with help of Axios. It helps users to do minimal changes to load live data. Users just need to change the mock API URL to the Live service URL.

### How does it work?

Axios have been configured in the folder **`..src\utils\axios.js`**

To use Axios on a page, you need to import it and make a call. It is used from slices here:  `src\store\reducers.` You need to call slice action from your page like below:

{% code title="src\pages\apps\chat.js" %}

```javascript
...
import { getUser } from 'store/reducers/chat';
...

const Chat = () => {
      const chatState = useSelector((state) => state.chat);
      ...    
      useEffect(() => {
        setUser(chatState.user);
      }, [chatState.user]);
      ...
      ...  
      useEffect(() => {
        // hide left drawer when email app opens
        ...
        dispatch(getUser(1));
        // eslint-disable-next-line react-hooks/exhaustive-deps
      }, []);
    
    ...
    ...
    
 }

export default Chat;
```

{% endcode %}

Mantis has all dummy data in the folder **`src\data.`** For API, **`api/chat/users`**, following data configured in **`..\src\data\chat.js`** :

{% code title="\chat\index.js" %}

```javascript
...

export const users = [
    {
        id: 1,
        name: 'Alene',
        company: 'ABC Pvt Ltd',
        role: 'Sr. Customer Manager',
        work_email: 'alene_work@company.com',
        personal_email: 'alene@company.com',
        work_phone: '380-293-0177',
        personal_phone: '380-293-0177',
        location: 'Port Narciso',
        avatar: 'avatar-1.png',
        status: 'Laboris non ad et',
        lastMessage: '2h ago',
        birthdayText: 'happy Birthday Alene',
        unReadChatCount: 2,
        online_status: 'available'
    },
    {
        id: 2,
        name: 'Keefe',
        company: 'ABC Pvt Ltd',
        role: 'Dynamic Operations Officer',
        work_email: 'keefe_work@gmil.com',
        personal_email: 'keefe@gmil.com',
        work_phone: '253-418-5940',
        personal_phone: '253-418-5940',
        location: 'Afghanistan',
        avatar: 'avatar-2.png',
        status: 'Laboris non ad et',
        lastMessage: '1:20 AM',
        birthdayText: 'happy Birthday Keefe',
        unReadChatCount: 3,
        online_status: 'available'
    }
    ...
    ...
];
...
...
];
...
...
});
```

{% endcode %}

You can configure the same for `post`methods as well.

### Next JS

Next js has a different mechanism to handle API. We have created `src/pages/api` folder where all the API stays. Whenever a request happened to API, this will be called. for more about API in nextJS, please refer: <https://nextjs.org/docs/api-routes/introduction>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://codedthemes.gitbook.io/mantis/v2.0.0/axios-api-calls.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
