Steps to run the flask application:
- Install the dependency packages to your virtual environment using requirements.txt. To do so run
pip install requirements.txt
after activating your virtual environment. - Create a folder named
data
and place thePlayers.csv
file in it. - Run the flask application by executing
app.py
or by running the commandflask run
. It runs onhttp://localhost:5000
.
API endpoints:
players
Query args:born-after
(optional),country
(optional)
Request patterns:http://localhost:5000/players?born-after=1981
Response:
{ "%players": 64.31095406360424, "players": [ { "Batting_Hand": "Right_Hand", "Bowling_Skill": "Right-arm medium", "Country": "India", "DOB": "24-Feb-91", "Player_Name": "A Ashish Reddy", "Year_of_Birth": 1991 }, ... ] }
http://localhost:5000/players?country=India
Response:
{ "country": "India", "players": [ { "Batting_Hand": "Right_Hand", "Bowling_Skill": "Right-arm medium", "Country": "India", "DOB": "24-Feb-91", "Player_Name": "A Ashish Reddy", }, ... ] }
http://localhost:5000/players?country=none
Response:
{ "country": "none", "players": [ { "Batting_Hand": "Right_hand", "Bowling_Skill": "Left-arm fast-medium", "Country":NaN, "DOB":NaN, "Player_Name": "A Choudhary" }, ... ] }
http://localhost:5000/players
Response:
{ "players": [ { "Batting_Hand": "Right_Hand", "Bowling_Skill": "Right-arm medium", "Country": "India", "DOB": "24-Feb-91", "Player_Name": "A Ashish Reddy" }, ... ] }
players/average-age
Request patterns:http://localhost:5000/players/average-age
Response:
{ "average-age": 36 }
http://localhost:5000/players/average-age?country=Australia
Response:
{ "average-age": 39, "country": "Australia" }
country/max-lefties
Request patterns:http://localhost:5000/country/max-lefties
Response:
{ "count": "58", "country": [ "India" ] }
Pytest files:
test_features.py
test_api.py
Note: Run test_api.py
test file only while running the flask app.