Built with the tools and technologies:
This FastAPI application provides a RESTful API with various endpoints for performing database operations, health checks, and versioning. The application includes CORS middleware for handling cross-origin requests and uses API key-based authentication for security.
- FastAPI Based Authentication
- Docker Image support
└── Dwellfi-assignment/
├── Dockerfile
├── README.md
├── app
│ ├── __init__.py
│ ├── classes
│ └── main.py
└── requirements.txt
Python: version 3.10.12
Build the project from source:
- Clone the Dwellfi-assignment repository:
❯ git clone https://github.com/mohit-217/Dwellfi-assignment
- Navigate to the project directory:
❯ cd Dwellfi-assignment
3.1 Install the required dependencies:
❯ pip install -r requirements.txt
3.2 Or build the docker image (Need to update docker-compose.yaml) :
❯ docker image build -t dwellfi-app .
Set the following environment variables before running the application:
OPENAI_API_KEY
: OpenAI API key (e.g.,sk-XXXXXXXXXXXXXXXXXXXXXX
)DB_Connection_url
: Database connection URL (e.g.,postgresql://user:password@localhost:5432/mydatabase
)Dwellfi_key
: Custom key for Dwellfi authentication (e.g.,your_dwellfi_key_here
)API_KEY
: API key for authenticating requests (e.g.,your_api_key_here
)
To run the project using uvicorn change .classes to classes and run below command: Create a .env file on the level of app directory:
❯ .env copy all environment variables
Navigate to the project directory:
❯ cd Dwellfi-assignment/app
❯ uvicorn main:app
To run the project using Docker Run the below command (need to update docker-compose.yaml)
❯ docker container run --publish 8080:8080 --name dwellfi-app-container dwellfi-app
- Endpoint:
/
- Method:
GET
- Parameters:
api_key
(string): The API key provided in the request header for authentication.
- Description: Returns a welcome message if the provided API key is valid.
- Response:
- Success: Returns a JSON response with a welcome message.
{ "message": "Welcome!" }
- Error: Returns an error message with status code
403
if the API key is invalid.
- Success: Returns a JSON response with a welcome message.
- Endpoint:
/health
- Method:
GET
- Parameters:
api_key
(string): The API key provided in the request header for authentication.
- Description: Returns the health status of the API.
- Response:
- Success: Returns a JSON response with the health status.
{ "status": "healthy" }
- Error: Returns an error message with status code
403
if the API key is invalid.
- Success: Returns a JSON response with the health status.
- Endpoint:
/version
- Method:
GET
- Parameters:
api_key
(string): The API key provided in the request header for authentication.
- Description: Returns the current version of the API.
- Response:
- Success: Returns a JSON response with the API version.
{ "version": "1.0.0" }
- Error: Returns an error message with status code
403
if the API key is invalid.
- Success: Returns a JSON response with the API version.
- Endpoint:
/perform_db_operation
- Method:
POST
- Parameters:
user_query
(string, form data): The user query to be executed on the database.api_key
(string): The API key provided in the request header for authentication.
- Description: Executes a database operation based on the provided user query.
- Response:
- Success: Returns the result of the database operation.(Read,Delete,Update or Insert record)
- Error: "Error Encounterd View stacktrace for detailed Explanation
- Endpoint:
/check_database_table
- Method:
POST
- Parameters:
api_key
(string): The API key provided in the request header for authentication.
- Description: Retrieves the latest record from the database table.
- Response:
- Success: Returns a JSON response with the latest record from the database.
- Error: Error Encounterd View stacktrace for detailed Explanation