https://github.com/sahil-172002/player
Cricket Player Management API using Node.js, Express.js, and MySQL for creating, reading, updating, and deleting player information.
https://github.com/sahil-172002/player
api backend curd express js mysql
Last synced: 2 months ago
JSON representation
Cricket Player Management API using Node.js, Express.js, and MySQL for creating, reading, updating, and deleting player information.
- Host: GitHub
- URL: https://github.com/sahil-172002/player
- Owner: sahil-172002
- Created: 2025-02-14T09:21:25.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-14T10:14:44.000Z (over 1 year ago)
- Last Synced: 2025-07-25T04:42:20.834Z (11 months ago)
- Topics: api, backend, curd, express, js, mysql
- Language: JavaScript
- Homepage:
- Size: 16.6 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 🏏 Cricket Player Management API
This is a backend API built with **Node.js**, **Express.js**, and **MySQL** for managing cricket player data, including creating, retrieving, updating, and deleting player information.
---
## 🚀 Features
- **Create Player:** Add new players with details like name, age, team, and position.
- **Retrieve Players:** Get all players or a specific player by ID.
- **Update Player:** Modify existing player details.
- **Delete Player:** Remove a player from the database.
---
## 🛠️ Tech Stack
- **Backend:** Node.js, Express.js
- **Database:** MySQL
- **Environment Variables:** dotenv
- **Dev Tools:** Nodemon
---
## 📂 Project Structure
---
## ⚙️ Installation
1. Clone the repository:
```bash
git clone https://github.com/your-username/player-backend.git
cd player-backend
```
2. Install dependencies:
```bash
npm install
```
3. Create a `.env` file in the root directory with the following:
```env
DB_HOST=your_host
DB_USER=your_username
DB_PASSWORD=your_password
DB_NAME=your_database_name
PORT=5000
```
4. Start the development server:
```bash
npm run dev
```
---
## 📋 API Endpoints
### ➕ Create a Player
- **URL:** `/api/players`
- **Method:** `POST`
- **Payload (JSON):**
```json
{
"name": "John Doe",
"age": 25,
"team": "Team A",
"position": "Batsman"
}
```
- **Response:**
```json
{
"message": "Player created successfully",
"playerId": 1
}
```
---
### 🔍 Get All Players
- **URL:** `/api/players`
- **Method:** `GET`
- **Response:**
```json
[
{
"id": 1,
"name": "John Doe",
"age": 25,
"team": "Team A",
"position": "Batsman"
}
]
```
---
### 🔍 Get Player by ID
- **URL:** `/api/players/:id`
- **Method:** `GET`
- **Example:** `/api/players/1`
- **Response:**
```json
{
"id": 1,
"name": "John Doe",
"age": 25,
"team": "Team A",
"position": "Batsman"
}
```
---
### ✏️ Update Player
- **URL:** `/api/players/:id`
- **Method:** `PUT`
- **Payload (JSON):**
```json
{
"name": "Jane Doe",
"age": 26
}
```
- **Response:**
```json
{
"message": "Player updated successfully"
}
```
---
### ❌ Delete Player
- **URL:** `/api/players/:id`
- **Method:** `DELETE`
- **Response:**
```json
{
"message": "Player deleted successfully"
}
```
---
## 🗃️ Database Schema
```sql
CREATE TABLE players (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100),
age INT,
team VARCHAR(100),
position VARCHAR(100),
matches_played INT DEFAULT 0,
runs_scored INT DEFAULT 0,
wickets_taken INT DEFAULT 0,
batting_average FLOAT DEFAULT 0,
bowling_average FLOAT DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);