|
| 1 | +# Employee Management API |
| 2 | + |
| 3 | +This application is a simple employee management API built using Python's Sanic framework and PostgreSQL for data storage. It allows you to perform basic CRUD (Create, Read, Update, Delete) operations on employee records. |
| 4 | + |
| 5 | +## Table of Contents |
| 6 | + |
| 7 | +- [Introduction](#introduction) |
| 8 | +- [Pre-Requisites](#pre-requisites) |
| 9 | +- [Installation](#installation) |
| 10 | +- [API Endpoints](#api-endpoints) |
| 11 | + - [Create Employee](#create-employee) |
| 12 | + - [Get All Employees](#get-all-employees) |
| 13 | + - [Get Employee by ID](#get-employee-by-id) |
| 14 | + - [Update Employee](#update-employee) |
| 15 | + - [Delete Employee](#delete-employee) |
| 16 | +- [Testing](#testing) |
| 17 | +- [Wrapping it up](#wrapping-it-up) |
| 18 | + |
| 19 | +## Introduction |
| 20 | + |
| 21 | +🪄 Dive into the world of Employee Management and see how seamlessly Keploy integrated with Sanic and PostgreSQL. Buckle up, it's gonna be a fun ride! 🎢 |
| 22 | + |
| 23 | +## Pre-Requisites 🛠️ |
| 24 | + |
| 25 | +Before you begin, ensure you have the following installed: |
| 26 | + |
| 27 | +- **Python 3.x**: The programming language used for this application. You can download it from [python.org](https://www.python.org/downloads/). |
| 28 | +- **PostgreSQL**: The database system used for storing employee data. You can download it from [postgresql.org](https://www.postgresql.org/download/). |
| 29 | + |
| 30 | +## Installation 📥 |
| 31 | + |
| 32 | +Once you have the prerequisites set up, follow these steps: |
| 33 | + |
| 34 | +1. Clone the repository: |
| 35 | + |
| 36 | + ```bash |
| 37 | + git clone https://github.com/keploy/sample-python.git |
| 38 | + cd sample-python |
| 39 | +Install the required Python packages: |
| 40 | + |
| 41 | +```bash |
| 42 | +pip install -r requirements.txt |
| 43 | +``` |
| 44 | + |
| 45 | +Set up your PostgreSQL database and update the connection settings in your application as needed. |
| 46 | + |
| 47 | +Install the latest Keploy binary: |
| 48 | + |
| 49 | +```bash |
| 50 | +curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz" | tar xz -C /tmp |
| 51 | +sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy |
| 52 | +``` |
| 53 | +Add alias for Keploy: |
| 54 | + |
| 55 | +```bash |
| 56 | +alias keploy='sudo docker run --pull always --name keploy-v2 -p 16789:16789 --privileged --pid=host -it -v "$(pwd)":/files -v /sys/fs/cgroup:/sys/fs/cgroup -v /sys/kernel/debug:/sys/kernel/debug -v /sys/fs/bpf:/sys/fs/bpf -v /var/run/docker.sock:/var/run/docker.sock -v '"$HOME"'/.keploy-config:/root/.keploy-config -v '"$HOME"'/.keploy:/root/.keploy --rm ghcr.io/keploy/keploy' |
| 57 | +``` |
| 58 | +Install the dependencies: |
| 59 | + |
| 60 | +```bash |
| 61 | +pip3 install -r requirements.txt |
| 62 | +``` |
| 63 | +API Endpoints |
| 64 | +Create Employee |
| 65 | +To add a new employee: |
| 66 | + |
| 67 | +```bash |
| 68 | +curl -X POST http://localhost:8000/employees \ |
| 69 | +-H "Content-Type: application/json" \ |
| 70 | +-d '{ |
| 71 | + "first_name": "John", |
| 72 | + "last_name": "Doe", |
| 73 | + |
| 74 | + "position": "Developer", |
| 75 | + "salary": 60000 |
| 76 | +}' |
| 77 | +``` |
| 78 | +Get All Employees |
| 79 | +To retrieve all employees: |
| 80 | + |
| 81 | +```bash |
| 82 | +curl -X GET http://localhost:8000/employees |
| 83 | +``` |
| 84 | + |
| 85 | +Get Employee by ID |
| 86 | +To retrieve a specific employee by ID: |
| 87 | + |
| 88 | +```bash |
| 89 | +curl -X GET http://localhost:8000/employees/1 |
| 90 | +``` |
| 91 | +Update Employee |
| 92 | +To update an existing employee's details: |
| 93 | +
|
| 94 | +```bash |
| 95 | +curl -X PUT http://localhost:8000/employees/1 \ |
| 96 | +-H "Content-Type: application/json" \ |
| 97 | +-d '{ |
| 98 | + "first_name": "Jane", |
| 99 | + "last_name": "Doe", |
| 100 | + |
| 101 | + "position": "Senior Developer", |
| 102 | + "salary": 80000 |
| 103 | +}' |
| 104 | +``` |
| 105 | +Delete Employee |
| 106 | +To delete an employee: |
| 107 | +
|
| 108 | +```bash |
| 109 | +curl -X DELETE http://localhost:8000/employees/1 |
| 110 | +``` |
| 111 | +Testing |
| 112 | +Capture Test Cases |
| 113 | +Capture the test cases using Keploy: |
| 114 | +
|
| 115 | +```bash |
| 116 | +keploy record -c "python3 server.py" |
| 117 | +``` |
| 118 | +Run Tests |
| 119 | +Run the tests: |
| 120 | +
|
| 121 | +```bash |
| 122 | +keploy test -c "python3 server.py" |
| 123 | +``` |
| 124 | +Wrapping it up 🎉 |
| 125 | +Congrats on the journey so far! You've seen how to manage employees seamlessly with Keploy, Sanic, and PostgreSQL. Keep exploring, innovating, and creating! With the right tools, anything's possible. 😊🚀 |
| 126 | +
|
| 127 | +Happy coding! ✨👩💻👨💻✨ |
0 commit comments