# APIs Calling

Crema has some **predefined hooks and functions to call the APIs** without writing redundant code like sending tokens and other extra configurations in APIs. \
\
These functions are directly linked with your authentication method as well, so you don't need anything special to call APIs without any extra setup.

1. **GET**: to fetch the data from the API. We can use this pre-defined hook&#x20;

```javascript
   const [
    {apiData, loading, initialUrl},
    {setData, setLoading, updateInitialUrl, setQueryParams, reCallAPI},
  ] = useGetDataApi('/dashboard/academy', {data: []}, {page: 1, perPage: 10});
```

2. **POST**: To save data using the API function

```javascript

const infoViewActionsContext = useInfoViewActionsContext(); 
 
postDataApi('/wall/posts', infoViewActionsContext, {
    post,
  })
    .then((data) => {
    // Do anything that you want here
      infoViewActionsContext.showMessage('Post Created Successfully!');
    })
    .catch((error) => {
      infoViewActionsContext.fetchError(error.message);
    });

```

3. **PUT**: To save data using the API function

```javascript
const infoViewActionsContext = useInfoViewActionsContext(); 

putDataApi('/wall/posts/${post.id}', infoViewActionsContext, {
    post,
  })
    .then((data) => {
    // Do anything that you want here
      infoViewActionsContext.showMessage('Post Updated Successfully!');
    })
    .catch((error) => {
      infoViewActionsContext.fetchError(error.message);
    });

```

4. **DELETE:** To Delete entry using the API function

<pre class="language-javascript"><code class="lang-javascript"><strong>
</strong>const infoViewActionsContext = useInfoViewActionsContext(); 
<strong>
</strong><strong>deleteDataApi('/wall/posts/${post.id}', infoViewActionsContext)
</strong>    .then((data) => {
    // Do anything that you want here
      infoViewActionsContext.showMessage('Post Deleted Successfully!');
    })
    .catch((error) => {
      infoViewActionsContext.fetchError(error.message);
    });

</code></pre>


---

# 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://docs.cremawork.com/v-4-nextjs/decelopment/axios-config/apis-calling.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.
