A simple Employee CRUD (Create, Read, Update, Delete) REST API built using Python and Flask, with SQLite as the database. This API allows you to manage employee records, including creating new employees, retrieving employee details, updating existing employee information, and deleting employees.
- Retrieve all employees
- Retrieve an employee by their ID
- Create a new employee
- Update an existing employee's details
- Delete an employee
- Python 3.6+
- Flask
- SQLite
-
Clone the repository:
git clone https://github.com/msnonari/Employee-REST-API.git cd Employee-REST-API -
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the required packages:
pip install -r requirements.txt
-
Create the SQLite database and the
Employeetable:sqlite3 EmpData.db < schema.sql
-
Run the Flask application:
python app.py
-
The API will be available at
http://127.0.0.1:5000.
GET /: Home route to check if the API is running.GET /emp: Retrieve all employees.GET /emp/<int:emp_id>: Retrieve an employee by their ID.POST /emp: Create a new employee.PUT /emp/<int:emp_id>: Update an existing employee's details.DELETE /emp/<int:emp_id>: Delete an employee.
curl -X GET http://127.0.0.1:5000/empcurl -X GET http://127.0.0.1:5000/emp/1curl -X POST http://127.0.0.1:5000/emp -H "Content-Type: application/json" -d '{"first_name": "John", "last_name": "Doe", "age": 30, "email": "john.doe@example.com", "gender": "Male", "job_title": "Developer", "department": "IT", "salary": 60000, "hire_date": "2023-10-01"}'curl -X PUT http://127.0.0.1:5000/emp/1 -H "Content-Type: application/json" -d '{"first_name": "John", "last_name": "Doe", "age": 31, "department": "HR"}'curl -X DELETE http://127.0.0.1:5000/emp/1To create the SQLite database and import the schema, follow these steps:
-
Open a terminal and navigate to the project directory:
cd path/to/Employee-REST-API -
Open the SQLite command line interface:
sqlite3 EmpData.db
-
Import the
schema.sqlfile to create theEmployeetable and insert records:.read schema.sql
-
Verify that the
Employeetable has been created and records have been inserted:.tables SELECT * FROM Employee;
This will create the Employee table and insert the initial records as defined in the schema.sql file.
This project is licensed under the MIT License.
Contributions are welcome! If you have any ideas, suggestions, or improvements, feel free to open an issue or submit a pull request.
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch). - Make your changes.
- Commit your changes (
git commit -m 'Add some feature'). - Push to the branch (
git push origin feature-branch). - Open a pull request.
Please make sure to update tests as appropriate.
Thank you for your interest in contributing to this project!