Skip to main content
At this stage of the course, we are going to build a working prototype of our Employee Management System (EMS) using in-memory data structures (dictionaries and lists) to represent our database. This will help us focus entirely on FastAPI routing, request validation, and response models.

1. In-Memory Data Flow

Since we are not yet using a database, our application’s state lives in the server’s RAM. Incoming HTTP requests read from or write to a global Python dictionary.
[!WARNING] Because this state lives in RAM, restarting the Uvicorn server or modifying your code (triggering a reload) will wipe the memory and reset the data back to its initial mock state.

2. Setting Up the Complete CRUD Code

Let’s write a complete, standalone file named ems_app.py in your project folder to demonstrate a full CRUD API:

3. Running and Testing the CRUD Operations

Start the application with Uvicorn:
You can test the endpoints directly using interactive API documentation pages like Swagger UI (available at http://127.0.0.1:8000/docs). Try:
  1. Sending a POST request to /employees to add a new employee.
  2. Sending a GET request to /employees to verify the new employee is listed.
  3. Sending a PUT request to /employees/1 to modify an employee’s department.
  4. Sending a DELETE request to /employees/2 to remove an employee, verifying you receive a 204 No Content status.