This API is designed to make it easier to implement login and registration features in your application without starting from scratch. It’s built with JWT (JSON Web Token) authentication, ensuring security and modern standards. The API is modular and can be easily customized according to your application's needs. In addition to user authentication, it also includes endpoints for managing products and searching ingredients, making it a versatile solution for various use cases.
- User registration and login functionality.
- JWT-based authentication.
- Secure database handling with SQLAlchemy.
- Easy-to-use API endpoints.
- Dockerized for smooth deployment.
The complete API documentation can be accessed through the following this link.
- Python 3.8 or later
- Docker (for containerized deployment)
- Google Cloud SDK (for deployment to Google Cloud Run)
-
Google Cloud Project
- Create or select an existing project in the Google Cloud Console.
-
Google Cloud Secret Manager
- Store sensitive data like
jwt_secret_key,database_url, andgcs_service_account_keyin Google Cloud Secret Manager.
- Store sensitive data like
-
Database Setup
- Set up your database (SQLite, PostgreSQL, or MySQL) and note the connection string.
-
Environment Variables
- Create a
.envfile in your project directory with the following variables:JWT_SECRET_KEY=your_secret_key DATABASE_URL=your_database_url GCS_SERVICE_ACCOUNT_KEY=path_to_your_service_account_key.json
- Create a
- Install and authenticate:
Install Google Cloud SDK:
Initialize the SDK:
curl https://sdk.cloud.google.com | bashAuthenticate:gcloud init
gcloud auth application-default login
- Cloning the Repository
Follow these steps to clone the repository and navigate to the project folder:
git clone <repository_url>
cd <project_folder>- Installing Requirements Install the required dependencies using pip:
pip install -r requirements.txt
- Running the FastAPI Application
Update the run configuration in
main.py:
port = int(os.environ.get('PORT', 8000)) # Use any desired port number
print(f"Listening to http://localhost:{port}")
uvicorn.run(app, host='localhost', port=port)- Start the local server using the following command:
uvicorn main:app --reload- Accessing the API Visit http://localhost:8000 in your browser or use tools like Postman to interact with the API.
git clone <repository_url>
# Change to the destined directory
cd <project_folder>
# Create a Docker Artifact Repository in a specified region
gcloud artifacts repositories create YOUR_REPOSITORY_NAME --repository-format=docker --location=YOUR_REGION
# Build Docker image for the ML API
docker buildx build --platform linux/amd64 -t YOUR_IMAGE_PATH:YOUR_TAG --build-arg PORT=8080 .
# Push the Docker image to the Artifact Repository
docker push YOUR_IMAGE_PATH:YOUR_TAG
# Deploy the Docker image to Cloud Run with allocated memory
gcloud run deploy --image YOUR_IMAGE_PATH:YOUR_TAG --memory 3Gi
# Fetching the service account associated with the newly deployed Cloud Run service
SERVICE_ACCOUNT=$(gcloud run services describe YOUR_SERVICE_NAME --platform=managed --region=YOUR_REGION --format="value(serviceAccountEmail)")
# Grant necessary IAM roles to the service account linked to the Cloud Run service
gcloud projects add-iam-policy-binding YOUR_PROJECT_ID --member=serviceAccount:${SERVICE_ACCOUNT} --role=roles/secretmanager.secretAccessor
gcloud projects add-iam-policy-binding YOUR_PROJECT_ID --member=serviceAccount:${SERVICE_ACCOUNT} --role=roles/cloudsql.client