|
1 |
| -# example-python-application |
2 |
| -Sample python application |
| 1 | +# Example Python Application |
| 2 | + |
| 3 | +This is a sample Python application built using **FastAPI**. The application allows users to submit their name and favorite color, and provides endpoints to retrieve the submitted data. It also includes logging functionality with JSON formatting. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **FastAPI** for building RESTful APIs. |
| 8 | +- **Pydantic** for data validation and serialization. |
| 9 | +- **Logging** with JSON formatting using `python-json-logger`. |
| 10 | +- In-memory storage for demonstration purposes. |
| 11 | + |
| 12 | +## Endpoints |
| 13 | + |
| 14 | +### Root Endpoint |
| 15 | +- **GET** `/` |
| 16 | + - Returns a welcome message. |
| 17 | + |
| 18 | +### Healthcheck |
| 19 | +- **GET** `/healthcheck` |
| 20 | + - Verifies if the service is running. |
| 21 | + |
| 22 | +### Submit User Color |
| 23 | +- **POST** `/usercolour/` |
| 24 | + - Accepts a user's name and favorite color. |
| 25 | + - **Request Body**: |
| 26 | + ```json |
| 27 | + { |
| 28 | + "name": "John Doe", |
| 29 | + "favorite_color": "Blue" |
| 30 | + } |
| 31 | + ``` |
| 32 | + - **Response**: |
| 33 | + ```json |
| 34 | + { |
| 35 | + "name": "John Doe", |
| 36 | + "favorite_color": "Blue" |
| 37 | + } |
| 38 | + ``` |
| 39 | + |
| 40 | +### Get All User Colors |
| 41 | +- **GET** `/allusercolour/` |
| 42 | + - Returns all submitted user-color mappings. |
| 43 | + |
| 44 | +## Installation |
| 45 | + |
| 46 | +* Clone the repository: |
| 47 | + ```bash |
| 48 | + git clone https://github.com/githubofkrishnadhas/example-python-application.git |
| 49 | + cd example-python-application |
| 50 | + ``` |
| 51 | + |
| 52 | +* Install dependencies using Poetry: |
| 53 | + |
| 54 | +``` |
| 55 | +poetry install |
| 56 | +``` |
| 57 | + |
| 58 | +Run the application: |
| 59 | + |
| 60 | +``` |
| 61 | +poetry run uvicorn app.quickapi:app --reload |
| 62 | +``` |
| 63 | +Access the API documentation at http://127.0.0.1:8000/docs. |
| 64 | + |
| 65 | +## Project Structure |
| 66 | +```yaml |
| 67 | +example-python-application/ |
| 68 | +├── app/ |
| 69 | +│ ├── data_model.py # Defines the Pydantic models |
| 70 | +│ ├── logging_config.py # Configures logging for the application |
| 71 | +│ ├── quickapi.py # Main FastAPI application |
| 72 | +├── README.md # Project documentation |
| 73 | +├── pyproject.toml # Poetry configuration |
| 74 | +``` |
| 75 | + |
| 76 | +## Dependencies |
| 77 | +* Python: 3.11+ |
| 78 | +* FastAPI: For building APIs. |
| 79 | +* Uvicorn: ASGI server for running the application. |
| 80 | +* Pydantic: Data validation and settings management. |
| 81 | +* python-json-logger: JSON formatting for logs. |
0 commit comments