This is simple Api which has two models employees and its departments.
-
Clone the repository:
git clone https://github.com/your-username/employee-management-api.git
-
Navigate to the project directory:
cd ROR_Employee_Management_Api
-
Install dependencies:
bundle install
-
Create a
.env
file in the root directory and add the following configuration:
DATABASE_NAME
: Name of the database.DATABASE_USERNAME
: Database username.DATABASE_PASSWORD
: Database password.DATABASE_HOST
: Database host.DATABASE_PORT
: Database port.
This project uses a database for storing employee data. It is running on Postgresql locally.You can configure the .env as above.
curl -X POST \
http://127.0.0.1:3000/departments \
-H 'Content-Type: application/json' \
-d '{
"department": {
"name": "computer"
}
}'
curl -X POST http://localhost:3000/employees \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"age": 21,
"salary":2000,
"email": "[email protected]",
"department_id": 1,
"position": "Software Engineer"
}'
curl http://localhost:3000/employees
curl http://localhost:3000/employees/<employee_id>
Replace <employee_id>
with the ID of the employee you want to retrieve.
curl -X PUT http://localhost:3000/employees/<employee_id> \
-H "Content-Type: application/json" \
-d '{
"name": "Updated Name",
"age": "Updated Age",
"salary": "Updated Salary",
"email": "[email protected]",
"department": "Updated Department",
"position": "Updated Position"
}'
Replace <employee_id>
with the ID of the employee you want to update.
curl -X DELETE http://localhost:3000/employees/<employee_id>
Replace <employee_id>
with the ID of the employee you want to delete.
Start the server using the following command:
rails s