This is an e-commerce application with RESTful API endpoints to manage products and categories. It includes functionality for user registration and login using JWT for authentication.
- Node.js (v14.x or later)
- MySQL (v8.x or later)
-
Clone the Repository
git clone https://github.com/Smoke221/all-sports-backend cd all-sports-backend
-
Install Dependencies
npm install
-
Setup Environment Variables
Create a
.env
file in the root directory of the project and add the following variables:DB_HOST=your_mysql_host DB_USER=your_mysql_user DB_PASSWORD=your_mysql_password DB_NAME=your_mysql_database JWT_SECRET=your_jwt_secret
-
Database Setup Make sure MySQL is running and create the required database and tables. You can use the provided SQL scripts or manually create them.
Example SQL for creating categories and products tables:
CREATE TABLE categories ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL ); CREATE TABLE products ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL, price DECIMAL(10, 2) NOT NULL, category_id INT, FOREIGN KEY (category_id) REFERENCES categories(id) );
-
Start the application
npm start
Try out using Swagger here
-
Register a New User
- Endpoint:
POST /auth/register
- Endpoint:
-
Login User
- Endpoint:
POST /auth/login
- Endpoint:
-
Retrieve All Categories
- Endpoint:
GET /categories
- Endpoint:
-
Retrieve a Category by ID
- Endpoint:
GET /categories/{id}
- Endpoint:
-
Create a New Category
- Endpoint:
POST /categories
- Endpoint:
-
Update a Category by ID
- Endpoint:
PUT /categories/{id}
- Endpoint:
-
Delete a Category by ID
- Endpoint:
DELETE /categories/{id}
- Endpoint:
-
Retrieve All Products
- Endpoint:
GET /products
- Endpoint:
-
Retrieve a Product by ID
- Endpoint:
GET /products/{id}
- Endpoint:
-
Create a New Product
- Endpoint:
POST /products
- Endpoint:
-
Update a Product by ID
- Endpoint:
PUT /products/{id}
- Endpoint:
-
Delete a Product by ID
- Endpoint:
DELETE /products/{id}
- Endpoint: