API to manage space ship counts for each all teams.
Running the api.py python module will initialize a 'teams.db' sqlite3 database, built with the Teams() model.
pip install -r requirements.txt
$ python api.py
Increments a team's guardian ship count.
/teams/<teamNum>/guardian [POST]
curl -b COOKIE -v -H "Content-Type: application/json" -X POST -d '{"value" : [NUMBER OF SHIPS]}' http://127.0.0.1:5000/teams/<teamNum>/guardian
{
'message': 'Team 2 has built X guardian ships'
}
Increments a team's bomber ship count.
/teams/<teamNum>/bomber [POST]
curl -b COOKIE -v -H "Content-Type: application/json" -X POST -d '{"value" : [NUMBER OF SHIPS]}' http://127.0.0.1:5000/teams/<teamNum>/bomber
{
'message': 'Team 2 has built X bomber ships'
}
Increments a team's striker ship count.
/teams/<teamNum>/striker [POST]
curl -b COOKIE -v -H "Content-Type: application/json" -X POST -d '{"value" : [NUMBER OF SHIPS]}' http://127.0.0.1:5000/teams/<teamNum>/striker
{
'message': 'Team 2 has built striker ships'
}
Creates a new team in the database with zeroed ships. Whiteteam authenticated.
/createteam [POST]
curl -b COOKIE -v -H "Content-Type: application/json" -X POST -d '{"teamNum" : [TEAM NUMBER], "name" : "[TEAM NAME]"}' http://127.0.0.1:5000/createteam
teamNum(integer)- the team number
name(string) - the team name
{
'teamNum' : 2, 'name' : 'Blue Team 2'
}
{
'message': 'Team 2 - Blue Team 2 created'
}
Deletes an existing team in the database. Whiteteam authenticated.
/deleteteam/<teamNum> [DELETE]
curl -b COOKIE -v -X DELETE http://127.0.0.1:5000/deleteteam/<teamNum>
teamNum(integer)- the team number
{
'message': 'Team 2 deleted'
}
Returns JSON of all the teams in the database. White team authenticated.
/teams [GET]
curl -b COOKIE -v http://127.0.0.1:5000/teams
{
"teams": [
{
"bomber": 0,
"damage": 125,
"guardian": 0,
"health": 100,
"name": "Blue Team 2",
"speed": 100,
"striker": 0,
"teamNum": 2
},
{
"bomber": 0,
"damage": 100,
"guardian": 0,
"health": 100,
"name": "Blue Team 3",
"speed": 100,
"striker": 0,
"teamNum": 3
}
]
}
Returns JSON of the team requested. White team authenticated.
/teams/<teamNum> [GET]
curl -b COOKIE -v http://127.0.0.1:5000/teams/<teamNum>
{
"bomber": 7,
"damage": 125,
"guardian": 10,
"health": 100,
"name": "Blue Team 2",
"speed": 100,
"striker": 1,
"teamNum": 2
}
Overrides any ship's count. White team authenticated.
/teams/<teamNum> [POST]
curl -b COOKIE -v -H "Content-Type: application/json" -X POST -d '{'guardian' : [COUNT], 'bomber' : [COUNT], 'striker' : [COUNT]}' http://127.0.0.1:5000/teams/<teamNum>
guardian - guardian ship count
bomber - bomber ship count
striker - heavy ship count
damage - percentage of damage
speed - percentage of speed
health - percentage of health
{
'guardian' : 2, 'bomber' : 0, 'striker' : 3, 'damage' : 100, 'speed' : 125, 'health : 25
}
{
'message': 'Team 2 is updated to guardian 2, bomber 0, striker 3, damage 100, speed 125, health 25'
}
Reset's a team to default values
/teams/<teamNum>/reset [PUT]
curl -b COOKIE -v -H "Content-Type: application/json" -X PUT http://127.0.0.1:5000/teams/<teamNum>/reset
{
'message': 'Team 2 has been reset'
}
Boost a team's attribute by however much is passed.
/teams/<teamNum>/boost [POST]
curl -b COOKIE -v -H "Content-Type: application/json" -X POST -d '{"type" : damage, speed, or health, "change" : "increase or decrease", "value" : 25}' http://127.0.0.1:5000/teams/<teamNum>/boost
{
'message' : 'Team X [change]'d their [type] by [value]'
}
- Flask - The web framework used
- SQLAlchemy - Database management
- sqlite3 - Database
- Brandon Dossantos