- launch the terminal
- change the dirctory to where the file is unziped.
- run
docker-compose build
to build containers form docker-compose.yaml file - after build run
docker-compose up -d
this activate containers in detached mode - check running container
docker ps --all
- for any debug use
docker logs <name of container>
to check for error raised while activating - now container are
UP
and runing - you can use any thing like curl,postman to access the fully operate the API
- you can access to api at
localhost:5000/
and propagate furter for more function - it resourses
/delete
acceptdelete
request delete_one in the collection with try except to catch some common exceptions/read
acceptget
request find_one in the collection with try except to catch some common exceptions/update
acceptput
request update_one in the collection with try except to catch some common exceptions/create
acceptpost
request insert_one in the collection with try except to catch some common exceptions/create-multi
acceptpost
request insert_many in the collection with try except to catch some common exceptions/
acceptget
request check if API isUP
/count_discounted_products
acceptget
request/list_unique_brands
acceptget
request/count_high_offer_price
acceptget
request/count_high_discount
acceptget
request
- List
- set the json below with change in
data->new->name
- and send the request with it to
/read
- recive a custom json response.
- it list all the record having the same name
- the quaries must not allow duplicate name
- but the collection may contain duplicate record as they are dumped
- set the json below with change in
- Add
- set the json below with change in
data->new
if want to insert only one or insert multipledata-multi
having array of entries as your data - and send the request with it to
/create
or/create-multi
- recive a custom json response.
- the quarie for single not allow duplicate name
- where as multiple user must ensure that there is no duplicate value
- set the json below with change in
- Delete
- set the json below with change in
data->new->name
- for deleting a entry
- and send the request with it to
/delete
- set the json below with change in
- Update
- set the json below with change in
data->set
including what to update anddata->new->name
including where to update with - and send the request with it to
/update
- set the json below with change in
{
"cred": {
"ID": "main",
"password": "loopd"
},
"data-multi": [
{
"name": "pqrs",
"brand_name": "wab",
"regular_price_value": "wab",
"offer_price_value": "wab",
"currency": "wab",
"classification_l1": "wab",
"classification_l2": "wab",
"classification_l3": "wab",
"classification_l4": "wab",
"image_url": "wab"
},
{
"name": "lmno",
"brand_name": "wab",
"regular_price_value": "wab",
"offer_price_value": "wab",
"currency": "wab",
"classification_l1": "wab",
"classification_l2": "wab",
"classification_l3": "wab",
"classification_l4": "wab",
"image_url": "wab"
}
],
"data": {
"new": {
"name": "new entry",
"brand_name": "wab",
"regular_price_value": "wab",
"offer_price_value": "wab",
"currency": "wab",
"classification_l1": "wab",
"classification_l2": "wab",
"classification_l3": "wab",
"classification_l4": "wab",
"image_url": "wab"
},
"set": {
"name": "set this",
"brand_name": "wab2",
"regular_price_value": "wab",
"offer_price_value": "wab",
"currency": "wab",
"classification_l1": "wab",
"classification_l2": "wab",
"classification_l3": "wab",
"classification_l4": "wab",
"image_url": "wab"
}
}
}
version: '3' #docker compose version 3
services: #creating two services web and db
web: #specifying metadata for flaskapi
build: ./web #directing to folder web to create the container with flaskapi
ports: #exposing to port 5000 of machine to 5000 of container
- "5000:5000"
links: #setting link to db container
- db
db: #specifying metadata for mongodb
build: ./db #directing to folder db to create the container with mongodb image
hostname: test_mongodb #giving host name
environment: #initialyzing database , username and password for mongodb environment
- MONGO_INITDB_DATABASE=newdb
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=pass
# download python 3 from docker hub or cached
FROM python:3 # download not only python 3, but also ubuntu operating system image layer
# instruct the image(ubuntu OS with python 3 installed), the working directory is /usr/src/app
WORKDIR /usr/src/app
# copy requirements.txt from local machine (the directory include the docker file)
# to current working directory /usr/src/app
COPY requirements.txt .
# install libraries listed in the requirements.txt on the Ubuntu machine
RUN pip install --no-cache-dir -r requirements.txt
# copy all the files from local machine to the ubuntu
COPY . .
# run python app.py to start the flask API
CMD ["python", "app.py"]
#creating container of mongo:3.6.4
FROM mongo:3.6.4
- launch the terminal
- change the dirctory to where the file is unziped.
- sudo docker-compose build
- sudo docker-compose up -d
MongoDB server > Database > Collections > Documents
Database is a physical container for collections where each database gets its own set of files of the file system.
Collection is a group of Mongo documents and it's equivalent of an RDBMS table. Collections do not enforce schema.
Document is a set of key value pairs and the documents have dynamic schema. Very similar to JSON