Skip to content

This Flask-based RESTful API provides a comprehensive backend solution for employee management.

Notifications You must be signed in to change notification settings

thiwankajayasiri/flask-api

Repository files navigation

codecov

TestPass

Employee Management API

A RESTful API for managing employees, built with Flask and Pydantic.

Table of Contents


Description

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.


Design Considerations

Project Considerations

  • 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.

Flask API Design Considerations

Detailed below are the design considerations for the API.

General Considerations

  1. Versioning
  2. Pagination
  3. Filtering and Sorting
  4. Rate Limiting
  5. Caching
  6. Throttling
  7. Logging and Monitoring

Endpoint-Specific Considerations

  • 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.


Dependencies

  • Python 3.10
  • Flask
  • Pydantic
  • Pytest
  • Locust

Installation

Detailed installation steps for both Poetry and Conda are provided.

Poetry

poetry install
poetry shell

Conda

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.

ENDPOINT URL

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}}

Testing

Unit Testing

# For Poetry
poetry run pytest

# For Conda
python -m pytest

Performance Testing

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

Contact

For any further queries, feel free to reach out1.


Footnotes

  1. My reference. For more elaborate issues or technical questions, please refer to the API Documentation.

About

This Flask-based RESTful API provides a comprehensive backend solution for employee management.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published