A Tic-tac-toe game API
- Create/Delete/Read Player details (/api/admin/players/)
- List players table (/api/admin/players/)
- Build ranking table for current season (/api/admin/ranking/)
- Start new season, list seasons (/api/admin/seasons/)
- Start game, list games statistics (/api/games/)
- Get game board data, make game turn (/api/games/<game_id>)
Note: Ranking table can be built by any season by passing season_id
as query argument:
/api/admin/ranking/?season_id=XXX
Note: Games stat list can be obtained for given season, player, draw result by passing corresponding query arguments:
/api/games/?season_id=XXX
/api/games/?player_id=XXX
/api/games/?is_draw=true
- Game API is based on Flask-RESTX
- Swagger Documentation (Part of Flask-RESTX).
- Unit Testing.
- Database ORM with Flask-SQLAlchemy
- Database Migrations using Flask-Migrate
- Object serialization/deserialization with Flask-Marshmallow
- Data validations with Marshmallow Marshmallow
- A Flask extension for handling Cross Origin Resource Sharing (CORS) Flask-CORS
Usage: flask [OPTIONS] COMMAND [ARGS]...
A general utility script for Flask applications.
Provides commands from Flask, extensions, and the application. Loads the
application defined in the FLASK_APP environment variable, or from a
wsgi.py file. Setting the FLASK_ENV environment variable to 'development'
will enable debug mode.
$ export FLASK_APP=tictactoe.py
$ export FLASK_ENV=development
$ flask run
Options:
--version Show the flask version
--help Show this message and exit.
Commands:
db Perform database migrations.
routes Show the routes for the app.
run Run a development server.
shell Run a shell in the app context.
test Run unit tests
Poetry
is recommended to help manage the dependencies and virtualenv.
You can also use other DBs like PostGreSQL
, make sure you have it setup and update your DATABASE_URL
in your configs.
Read more at Flask-SQLAlchemy's documentations.
It uses Black for code styling/formatting.
# Install packages with poetry
$ poetry install
Please specify your app's environment variables in a .env
file, otherwise Flask CLI wouldn't find your app.
# .env file example
FLASK_APP=tictactoe
FLASK_CONFIG=development
# Read more at https://github.com/theskumar/python-dotenv
$ cp .env_eample .env
# Enter the virtualenv
$ poetry shell
$ flask db init # Creates a new migration repository.
$ flask db migrate # Create a new revision file.
$ flask db upgrade # Upgrade to a later version.
# Run the app
$ flask run
You can make requests to API in swagger UI. Open in browser http://127.0.0.1:5000/api
# Unit testing
$ flask test
# Run specific unit test(s)
$ flask test test tests.test_models.TestModels.test_game_finished_winner ...