There are two ways of running the application locally
Using Docker
Using normal python env
Using docker
Make sure docker and docker compose is installed in your PC if not follow this steps
Clone the project in to your local machine
Run the following commands
cd <project_location>
docker-compose build
docker-compose up -d
This will run your application in localhost:5000 with mongodb running in port 27017
Using normal python env
Clone the git repo to your local
Install virtualenvironment in your pc
Create a new virtual env
Create a .env file with following env vars MONGO_URI APP_HOST APP_PORT
Follow the commands
cd <project_location>
pip install -r requirements.txt
flask run
Follow either of one your application should be running locally
API Reference
Get all users
GET /users
returns all the users in the batch of 10
Parameter
Type
Description
page
int
Optional defaultly we consider page as 1
Get a particular user
GET /users/${id}
Parameter
Type
Description
id
string
Required. Id of the user to fetch details
Add a User
POST /users
Parameter
Type
Description
name
string
Required.
email
string
Required. and should be valid email id
password
string
Required. and should be more than 6 chars long
PUT /users/${id}
Parameter
Type
Description
id
string
Required. else you will get validation error
DELETE /users/${id}
Parameter
Type
Description
id
string
Required. else you will get validation error
Screenshots
Get all users
Get user by ID
Add User
Update user
Delete a user
Additional information
In docker set up The mongo db is non-persistent When ever you start the application new db instance will be used
There a script called populate.py this is used to pre-populate the users data with faker library you can run this script to pre-populate 100 user data
How to run populate.py script
Run the docker-compose up -d
do docker ps
get the container id of flask_assignment_app
do docker exec -it <container_id> bash
you will get inside the container
then run python populate.py it should populate 100 users data