https://github.com/abhijeetanand45/restful_api
Employee Management REST API
https://github.com/abhijeetanand45/restful_api
express mysql-database mysql2 nodejs readme restapi restapi-example restful-api sql
Last synced: about 2 months ago
JSON representation
Employee Management REST API
- Host: GitHub
- URL: https://github.com/abhijeetanand45/restful_api
- Owner: AbhijeetAnand45
- Created: 2022-01-24T18:07:57.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-05-03T19:03:49.000Z (about 2 years ago)
- Last Synced: 2025-01-13T12:48:49.572Z (over 1 year ago)
- Topics: express, mysql-database, mysql2, nodejs, readme, restapi, restapi-example, restful-api, sql
- Language: JavaScript
- Homepage:
- Size: 3.73 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Employee Management REST API
This is a simple Node.js application that provides a RESTful API for managing employees in a MySQL database. It supports CRUD (Create, Read, Update, Delete) operations on the employee table.
## Prerequisites
Before running this application, ensure you have the following installed:
- Node.js
- MySQL server
## Installation
1. Clone the repository:
```
git clone https://github.com/your_username/Restful_API.git
```
2. Navigate to the project directory:
```
cd Restful_API
```
3. Install dependencies:
```
npm install
```
4. Set up your MySQL database:
- Create a MySQL database named `your_db_name`.
- Create an `employees` table with columns `id`, `name`, `email`, and `salary`.
5. Configure MySQL connection:
In `app.js`, update the MySQL connection details (host, user, password) according to your MySQL setup.
## Usage
Start the Node.js server:
```
node myapp.js
```
The server will start running on `http://localhost:3000`.
### API Endpoints
- **GET /employees**: Retrieves all employees.
- **GET /employees/:id**: Retrieves a specific employee by ID.
- **POST /employees**: Creates a new employee.
- **PUT /employees/:id**: Updates an existing employee by ID.
- **DELETE /employees/:id**: Deletes an existing employee by ID.
## Examples
### 1. GET /employees
- **URL:** `http://localhost:3000/employees`
- **Method:** GET
- **Description:** Retrieves all employees from the database.
**Response:**
```json
[
{
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"salary": 50000
},
{
"id": 2,
"name": "Jane Smith",
"email": "jane@example.com",
"salary": 60000
},
// More employee details...
]
```
### 2. GET /employees/:id
- **URL:** `http://localhost:3000/employees/:id`
- **Method:** GET
- **Description:** Retrieves a specific employee by their ID.
**Response:**
```json
{
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"salary": 50000
}
```
### 3. POST /employees
- **URL:** `http://localhost:3000/employees`
- **Method:** POST
- **Description:** Creates a new employee record in the database.
**Request:**
```json
{
"name": "Alice Cooper",
"email": "alice@example.com",
"salary": 55000
}
```
**Response:**
```json
{
"message": "Employee added successfully",
"id": 3
}
```
### 4. PUT /employees
- **URL:** `http://localhost:3000/employees/:id`
- **Method:** PUT
- **Description:** Updates an existing employee record identified by their ID.
**Request:**
```json
{
"name": "Alice Cooper",
"email": "alice@example.com",
"salary": 60000
}
```
**Response:**
```json
{
"message": "Employee updated successfully"
}
```
### 5. DELETE /employees/:id
- **URL:** `http://localhost:3000/employees/:id`
- **Method:** DELETE
- **Description:** Deletes an existing employee record identified by their ID.
**Response:**
```json
{
"message": "Employee deleted successfully"
}
```
> With Love, Abhijeet..