pranavpadmasali / quote-aws-fargate

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

REST backend for quote app.

Steps to run locally

  1. Clone the repository

  2. Create a virtual environment with python 3.8. using command

python3 -m venv venv
  1. Source virtual environment by

source venv/bin/activate

  1. Add the environment variables abd install dependencires
export MONGO_DB_PASSWORD=YOUR_DB_PASSWORD

export MONGO_DB_USERNAME=YOUR_USERNAME
pip  install  -r  requirements.txt
python  -m  spacy  download  en_core_web_lg
  1. Run the flask app with development server.
python app.py

To run flask with production server use gunicorn

gunicorn --bind 0.0.0.0:5000 app:app
  1. To build the docker image locally run
docker build --build-arg mongo_username=YOUR_USERNAME --build-arg mongo_password=YOUR_DB_PASSWORD -t quotes-app .
  1. To run the docker image locally run
docker run -d -p 9988:5000 quotes-app

Testing

The backend is deployed on aws fargate and aws gateway is currently used to terminate https and proxy the request to fargate task.

Get All quotes

curl --location --request GET 'https://2zbus46lel.execute-api.ap-south-1.amazonaws.com/v1/quote'

Get rated quotes

curl --location --request GET 'https://2zbus46lel.execute-api.ap-south-1.amazonaws.com/v1/getRatedQuote'

Update quote with rating

curl --location --request PUT 'https://2zbus46lel.execute-api.ap-south-1.amazonaws.com/v1/quote/5aa45f317832df00040ac9c0' \

--header 'Content-Type: application/json' \

--data-raw '{

"rating":4

}'

Get related quote similarity

curl --location --request POST 'https://2zbus46lel.execute-api.ap-south-1.amazonaws.com/v1/getRelatedQuote' \

--header 'Content-Type: application/json' \

--data-raw '{"quote":"automating your work is creativity"}'

Add new quote

curl --location --request POST 'https://2zbus46lel.execute-api.ap-south-1.amazonaws.com/v1/quote' \

--header 'Content-Type: application/json' \

--data-raw '{

"quotes":"here and there",

"author":"George O",

"rating":4

}'

Further Improvement

  1. Using flask blue prints.
  2. Saving intermidate semantic vectors in database so that they can be used for calculation.
  3. Terminating HTTPS using a Load

About


Languages

Language:Python 95.0%Language:Dockerfile 5.0%