Skip to content

Rinil-Parmar/ROR_Employee_Management_Api

Repository files navigation

Employee Management API

This is simple Api which has two models employees and its departments.

Setup

  1. Clone the repository:

    git clone https://github.com/your-username/employee-management-api.git
  2. Navigate to the project directory:

    cd ROR_Employee_Management_Api
  3. Install dependencies:

    bundle install
  4. Create a .env file in the root directory and add the following configuration:

Environment Variables

  • DATABASE_NAME: Name of the database.
  • DATABASE_USERNAME: Database username.
  • DATABASE_PASSWORD: Database password.
  • DATABASE_HOST: Database host.
  • DATABASE_PORT: Database port.

Database Configuration

This project uses a database for storing employee data. It is running on Postgresql locally.You can configure the .env as above.

Basic CRUD Operations

Create Department

curl -X POST \
  http://127.0.0.1:3000/departments \
  -H 'Content-Type: application/json' \
  -d '{
    "department": {
        "name": "computer"
    }
}'

Create an Employee

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"
}'

Read All Employees

curl http://localhost:3000/employees

Read a Single Employee

curl http://localhost:3000/employees/<employee_id>

Replace <employee_id> with the ID of the employee you want to retrieve.

Update an Employee

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.

Delete an Employee

curl -X DELETE http://localhost:3000/employees/<employee_id>

Replace <employee_id> with the ID of the employee you want to delete.

Running the Server

Start the server using the following command:

rails s

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published