Integration

.env.local

Ensure that the API integration is enabled by setting the variable in the .env.local file. Change the value of NEXT_PUBLIC_IS_API_ACTIVE to "true" instead of "false". This configuration activates the API features within the application, allowing it to make requests to the backend and retrieve or send data as needed. By doing so, you ensure that the application is properly connected to the API, facilitating seamless communication between the frontend and backend services.

NEXT_PUBLIC_IS_API_ACTIVE = "true"

The src/utils/axios_api.js file is responsible for managing all API interactions within the application. It centralizes the configuration and handling of HTTP requests using Axios, allowing for consistent and efficient communication with backend services. This file typically includes functions for making GET, POST, PUT, and DELETE requests, along with error handling and response processing. By organizing API calls in one location, it simplifies maintenance and enhances the scalability of the application.

src/utils/axios_api.js

import axios from 'axios';

const api = axios.create({
    baseURL: process.env.NEXT_PUBLIC_BASE_URL, // This won't be used but gives a sense of structure
});

// Mock GET request -- get data
api.get = async (url) => {
  ...
};


// Mock POST request -- add data
api.post = async (api, newRecord, field?) => {
    const isApiActive = process.env.NEXT_PUBLIC_IS_API_ACTIVE === "true";
    let data = [];

    if (isApiActive) {
        try {
          ...

        } catch (error) {
           ...
        }
    } else {
      ...
    }
};

// Mock PUT request -- update data
api.put = async (api, updatedRecord, field?) => {
    const isApiActive = process.env.NEXT_PUBLIC_IS_API_ACTIVE === "true";
    let data = [];

    if (isApiActive) {
        try {
          ...
        } catch (error) {
            ...
        }
    } else {
        ...
    }

};

// Mock DELETE request -- delete data
api.delete = async (api, id, field?) => {
    const isApi = process.env.NEXT_PUBLIC_IS_API_ACTIVE === "true";

    if (isApi) {
        ...
    } catch (error) {
        ...
    } else {
      ...
    }
};

export default api;

src/utils/url_helper.js

The src/utils/url_helper.js file centralizes API endpoints, enhancing maintainability, readability, and consistency while simplifying environment configuration in the application.

export const NEXT_PUBLIC_SCHOOL_PARENTS_LIST = '/api/parents'

src/pages/api/parents/index.js

The src/pages/api/parents/index.js file effectively manages parent-related data using API endpoints for CRUD operations. By implementing GET, POST, PUT, and DELETE methods, it allows the frontend to interact seamlessly with the data, facilitating dynamic content management in the application.

import fs from 'fs';
import path from 'path';

const dataFilePath = path.join(process.cwd(), 'your json data path');

const readData = () => {
	...    
};


const writeData = (data) => {
    try {
        ...
    } catch (error) {
       ...
    }
};

export default function handler(req, res) {
    switch (req.method) {
        // Read and return the Parents data
        case 'GET':
           ...
            break;

        // Create a Parents record API
        case 'POST': {
            try {
               ...
            } catch (error) {
              ...
            }
            break;
        }

        // Update a Parents record API
        case 'PUT': {
            try {
               ...
            } catch (error) {
              ...
            }
            break;
        }

        // Delete a Parents record API
        case 'DELETE': {
            try {
              ...
            } catch (error) {
               ...
            }
        }

        default:
            res.setHeader('Allow', ['GET', 'POST', 'PUT', 'DELETE']);
            res.status(405).end(`Method ${req.method} Not Allowed`);
            break;
    }
}

This guide covers everything you need to know to make sure Tailwind generates all of the CSS needed for your project.

Receive the latest updates directly in your inbox!

Be the first to know about new updates and exclusive discounts. No spam, just great offers!

How about

A Custom Project?

With over 7 years of experienced team, we specialize in delivering custom projects for startups, blue-chip companies, and government agencies. We have successfully completed over 250+ projects, providing tailored solutions that meet the unique needs of each client.

Hire Us
Domiex Admin & Dashboards
230+

Total Pages

5+

Layouts

11+

Application

We provide quick support withing one business day to all of our customers.

© Domiex Created & Crafted by SRBThemes.