API Utilities - AgroLogi/FreshShop GitHub Wiki

The API Utilities in the FreshShop application are responsible for managing all interactions with the backend. The backend is powered by Strapi CMS, and Axios is used to handle the HTTP requests from the frontend. This modular approach ensures that the frontend retrieves and posts data to the backend in real time.

1. Axios Client

A centralized Axios client is created to simplify API requests. The client dynamically sets the base URL for the backend API, allowing flexible deployment environments.

2. Key API Functions

The utility provides several important functions to interact with the backend:

  • Category Management: The app uses a dedicated function to fetch a list of product categories from the backend. This data is used to display product categories dynamically on the frontend.
  • Product Management: Functions are available to retrieve all product data, including product images, prices, and categories. Additionally, products can be filtered by category, allowing users to browse specific categories like "electronics" or "fashion."
  • User Authentication: Two key functions are provided for registering new users and logging in existing users. When users register, their details (username, email, and password) are sent to the backend. For login, the user's credentials are verified through the authentication API.
  • Cart Management: The cart operations include adding items to the cart, fetching the total number of cart items, and removing items from the cart. These functions ensure that users can manage their cart items dynamically as they shop.
  • Order Processing: Once the user proceeds to checkout, the order is posted to the backend through the createOrder function. This ensures that the order data is stored securely for processing. These API utilities act as the backbone of the app, facilitating data transfer and syncing between the frontend and backend systems.