Skip to content

Achanandhi-M/samples-python

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django MySQL CRUD Application

This application is a simple Employee Management System built with Django and MySQL. It allows you to create, retrieve, update, and delete employee records via RESTful API endpoints. The application is containerized using Docker, making it easy to deploy and run in different environments. The backend is powered by Django, and the MySQL database is used to store employee information.

Prerequisites

  • Docker

Steps to Run the Application

1. Build and Run MySQL Database Container

Run the db:

docker run --name mySQL --network keploy-network -e MYSQL_ROOT_PASSWORD=keploy -e MYSQL_DATABASE=keploy_db -e MYSQL_USER=admin -e MYSQL_PASSWORD=keploy -p 3306:3306 -d mysql

2. Build and Run Django Application Container

In the project root directory, run:

docker build --build-arg HOST_PWD="$(pwd)" -t py-app .

docker run --name django-app --net keploy-network -p 8000:8000 -v "$(pwd):$(pwd)" --rm py-app

3. API Endpoints

Create Employee (POST): http://localhost:8000/api/employee/create/

Get Employee by ID (GET): http://localhost:8000/api/employee/{id}/

Get All Employees (GET): http://localhost:8000/api/employee/

Update Employee (PUT): http://localhost:8000/api/employee/update/{id}/

Delete Employee (DELETE): http://localhost:8000/api/employee/delete/{id}/

Example Request Payload for Creating an Employee:

Now, you can send the following request payload to create a new employee with an additional field:

{
    "name": "John Doe",
    "years_of_experience": 5,
    "field": "Computer Science",
    "company": "TechCorp"
}

Example CURL for creating an employee:

curl -X POST http://localhost:8000/api/employee/create/ -H "Content-Type: application/json" -d '{"name": "John Doe", "years_of_experience": 5, "field": "Computer Science", "company": "TechCorp"}'

Notes:

Django application runs on port 8000.

Testing the APIs

Use the following curl commands to test the APIs after running the application:

POST Request to create an employee

curl -X POST http://localhost:8000/api/employee/create/ -H "Content-Type: application/json" -d '{"name": "John Doe", "years_of_experience": 5, "field": "Computer Science", "company": "TechCorp"}'

GET Request to fetch all employees

curl -X GET http://localhost:8000/api/employee/

GET Request to fetch an employee by ID

curl -X GET http://localhost:8000/api/employee/1/

PUT Request to update an employee

curl -X PUT http://localhost:8000/api/employee/update/1/ -H "Content-Type: application/json" -d '{"name": "Jane Doe", "years_of_experience": 6, "field": "Data Science", "company": "TechCorp"}'

DELETE Request to delete an employee

curl -X DELETE http://localhost:8000/api/employee/delete/1/

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 87.0%
  • Dockerfile 6.2%
  • JavaScript 3.9%
  • Shell 2.9%