Crema React
v-4 Nextjs
v-4 Nextjs
  • About Crema Next.js
  • Overview
    • Crema Next.js Overview
    • Folder Structure
      • @crema
      • app
      • assets
      • modules
      • style
    • Package.json
    • GitHub Access
    • Slack Community
    • Figma File
  • Decelopment
    • Installation
    • Route Management
    • Auth User
    • Authentication Methods
    • Axios Config
      • APIs Calling
    • Multilingual
  • MUI
    • Theme Color
    • Sidebar Configuration
    • Navigation Style
    • Footer Configuration
    • Template Direction
    • Template Mode
  • FAQ
  • ANTD
    • About Crema Ant
    • Style Framework
  • Crema V-3 Doc
  • Servers
    • Python
    • Laravel
    • Mongoose
  • Credits
Powered by GitBook
On this page

Was this helpful?

  1. Decelopment
  2. Axios Config

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.

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

   const [
    {apiData, loading, initialUrl},
    {setData, setLoading, updateInitialUrl, setQueryParams, reCallAPI},
  ] = useGetDataApi('/dashboard/academy', {data: []}, {page: 1, perPage: 10});
  1. POST: To save data using the API function


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);
    });
  1. PUT: To save data using the API function

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);
    });
  1. DELETE: To Delete entry using the API function


const infoViewActionsContext = useInfoViewActionsContext(); 

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

Was this helpful?