├── .gitignore ├── Readme.md ├── api ├── TaskAPI.py ├── TaskByIDAPI.py └── __init__.py ├── app.py └── reqirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | venv 2 | __pycache__ 3 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | ## Git clone the application 2 | 3 | ## Create a virtual environment inside the application 4 | 5 | ```python 6 | 7 | virtualenv -p /usr/bin/python3.4 venv 8 | 9 | source venv/bin/activate 10 | 11 | ``` 12 | 13 | ## Install Python modules 14 | 15 | ```python 16 | 17 | pip3.4 install -r requirements.txt 18 | 19 | ``` 20 | 21 | 22 | ## Run the application using 23 | 24 | ```python 25 | 26 | python app.py 27 | 28 | ``` 29 | 30 | 31 | ## You will get two REST API 32 | 33 | ```python 34 | 35 | http://localhost:5000/api/v1.0/task 36 | 37 | http://localhost:5000/api/v1.0/task/id/ 38 | 39 | ``` 40 | -------------------------------------------------------------------------------- /api/TaskAPI.py: -------------------------------------------------------------------------------- 1 | from flask_restful import Resource 2 | import logging as logger 3 | 4 | class Task(Resource): 5 | 6 | def post(self): 7 | logger.debug("Inside the post method of Task") 8 | return {"message" : "Inside post method"},200 9 | 10 | 11 | def get(self): 12 | logger.debug("Inisde the get method of Task") 13 | return {"message" : "Inside get method"},200 14 | 15 | def put(self): 16 | logger.debug("Inisde the put method of Task") 17 | return {"message" : "Inside put method"},200 18 | 19 | def delete(sef): 20 | 21 | logger.debug("Inisde the delete method of Task") 22 | return {"message" : "Inside delete method"},200 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /api/TaskByIDAPI.py: -------------------------------------------------------------------------------- 1 | from flask_restful import Resource 2 | import logging as logger 3 | 4 | class TaskByID(Resource): 5 | 6 | def post(self,taskId): 7 | logger.debug("Inside the post method of TaskById") 8 | return {"message" : "Inside post method of TaskByID. TaskId : {}".format(taskId)},200 9 | 10 | 11 | def get(self,taskId): 12 | logger.debug("Inisde the get method of TaskById. TaskID = {}".format(taskId)) 13 | return {"message" : "Inside get method of TaskByID. TaskByID = {}".format(taskId)},200 14 | 15 | 16 | def put(self,taskId): 17 | logger.debug("Inisde the put method of TaskByID. TaskID = {}".format(taskId)) 18 | return {"message" : "Inside put method of TaskById. TaskID = {}".format(taskId)},200 19 | 20 | 21 | def delete(self,taskId): 22 | logger.debug("Inisde the delete method of TaskByID. TaskID = {}".format(taskId)) 23 | return {"message" : "Inside delete method"},200 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /api/__init__.py: -------------------------------------------------------------------------------- 1 | from flask_restful import Api 2 | from app import flaskAppInstance 3 | from .TaskAPI import Task 4 | from .TaskByIDAPI import TaskByID 5 | 6 | 7 | restServerInstance = Api(flaskAppInstance) 8 | 9 | restServerInstance.add_resource(Task,"/api/v1.0/task") 10 | restServerInstance.add_resource(TaskByID,"/api/v1.0/task/id/") 11 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | import logging as logger 3 | logger.basicConfig(level="DEBUG") 4 | 5 | 6 | flaskAppInstance = Flask(__name__) 7 | 8 | 9 | 10 | if __name__ == '__main__': 11 | 12 | logger.debug("Starting Flask Server") 13 | from api import * 14 | flaskAppInstance.run(host="0.0.0.0",port=5000,debug=True,use_reloader=True) 15 | -------------------------------------------------------------------------------- /reqirements.txt: -------------------------------------------------------------------------------- 1 | aniso8601==3.0.2 2 | click==6.7 3 | Flask==1.0.2 4 | Flask-RESTful==0.3.6 5 | itsdangerous==0.24 6 | Jinja2==2.10 7 | MarkupSafe==1.0 8 | pytz==2018.5 9 | six==1.11.0 10 | Werkzeug==0.14.1 11 | --------------------------------------------------------------------------------