A RESTful API for managing employees, built with Flask and Pydantic.
Manage a list of employees with CRUD operations. Each employee has an id
, first_name
, last_name
, and position
. Data is temporarily stored in an in-memory list.
Note
Data is not persisted and will be lost once the server is stopped.
- RESTful API design
- Pydantic for data validation
- In-memory list as a mock database
- Supports both Poetry and Conda for dependency management
- Tested with pytest, pytest-flask, and Locust
- CI/CD pipeline via GitHub Actions
- Code quality assured by flake8 and mypy
Important
Always review code quality reports and test results in the CI/CD pipeline.
Detailed below are the design considerations for the API.
- Versioning
- Pagination
- Filtering and Sorting
- Rate Limiting
- Caching
- Throttling
- Logging and Monitoring
- Add (POST /employees)
- Read All (GET /employees)
- Read One (GET /employees/)
- Update (PUT /employees/)
- Delete (DELETE /employees/)
Please refer to comprehensive design decisions on the design_decisions.
Warning
Always check for a valid id
before performing update or delete operations to prevent accidental data loss.
- Python 3.10
- Flask
- Pydantic
- Pytest
- Locust
Detailed installation steps for both Poetry and Conda are provided.
poetry install
poetry shell
conda env create -f environment.yml
conda activate flask-app-employee
- Running the API
conda
flask run
poetry
poetry run flask run
For more comprehensive details, please refer to the API Documentation.
For detailed examples of API usage, please refer to the usage documentation.
Note
Use the ENDPOINT https://employee-api-stage-fd8d182a1891.herokuapp.com/
Heroku based deployment
please follow the usage pattern given on the usage_documentation, and replace the http://localhost:5000
with the above ENDPOINT URL.
e.g.
curl -X 'GET' 'https://employee-api-stage-fd8d182a1891.herokuapp.com/v1/employees'
result
{"data":[{"first_name":"John","id":1,"last_name":"Doe","position":"Engineer"},{"first_name":"Jane","id":2,"last_name":"Doe","position":"Manager"},{"first_name":"Mike","id":3,"last_name":"Johnson","position":"Developer"}],"meta":{"page":1,"per_page":10,"total_employees":3}}
# For Poetry
poetry run pytest
# For Conda
python -m pytest
navigate to api-perf-testing
directory
- conda
python -m locust
Note
Navigate to http://localhost:8089
to start the Locust performance test.
Sample performance test results can be found on the performance_results.
Warning
Due to some issues with Poetry, the performance test is not working with Poetry. Please use Conda for performance testing.
- poetry
poetry run python -m locust
For any further queries, feel free to reach out1.
Footnotes
-
My reference. For more elaborate issues or technical questions, please refer to the API Documentation. ↩