THIS PROJECT IS UNDER ACTIVE DEVELOPMENT, README MAY CHANGE EVERY ONCE IN A WHILE
This will be a free to use, open sourced questions database which has a REST API implemented in Python3 & Flask using PostgresSQL database, also this will be a source for a minimal quizzing website which will also let contributors add new questions in multiple categories and as MCQ or T/F types.
To use this project.
Development
If you want just to do a simple test run of the application, you can install and use it with development config.
- Clone the repository
$ git clone https://github.com/PyBites-Open-Source/questionnaire-api.git
- Create the virtualenv and activate it
$ cd questionnaire-api
$ python -m venv virtualenv
$ source virtualenv/bin/activate # unix
$ .\virtualenv\Scripts\activate # windows
- Install requirements
$ pip3 install -r ./src/requirements.txt
- Create database and apply migrations
$ cd src && flask db upgrade
- Run the application
$ cd src && flask run
Production
In order to use postgresql database ready for production, you need to use docker and to add some additional environment variables.
- Setup database
# create .env file wihtin src folder with the following environment variables.
POSTGRES_USER="trivia"
POSTGRES_PASSWORD="trivia"
POSTGRES_DB_PROD="opentrivia_prod"
POSTGRES_DB_TEST="opentrivia_test"
DB_PORT="5432"
DB_HOST="localhost"
# if you want to change these settings you have to change also the init.sql file
# from db folder.
- Run the application
$ cd src && docker-compose up
- Add a file structure here with the basic details about files, below is an example.
.
βββ docker
βΒ Β βββ api-server
βΒ Β βΒ Β βββ Dockerfile
βΒ Β βββ db-server
βΒ Β βββ Dockerfile
βββ logo
βΒ Β βββ opentrivia.png
βββ src
βΒ Β βββ app
βΒ Β βΒ Β βββ api
βΒ Β βΒ Β βΒ Β βββ routes
βΒ Β βΒ Β βΒ Β βΒ Β βββ __init__.py
βΒ Β βΒ Β βΒ Β βΒ Β βββ answers.py
βΒ Β βΒ Β βΒ Β βΒ Β βββ categories.py
βΒ Β βΒ Β βΒ Β βΒ Β βββ questions.py
βΒ Β βΒ Β βΒ Β βββ tests
βΒ Β βΒ Β βΒ Β βΒ Β βββ __init__.py
βΒ Β βΒ Β βΒ Β βΒ Β βββ test_answers.py
βΒ Β βΒ Β βΒ Β βΒ Β βββ test_categories.py
βΒ Β βΒ Β βΒ Β βΒ Β βββ test_questions.py
βΒ Β βΒ Β βΒ Β βββ __init__.py
βΒ Β βΒ Β βββ models
βΒ Β βΒ Β βΒ Β βββ __init__.py
βΒ Β βΒ Β βΒ Β βββ answer.py
βΒ Β βΒ Β βΒ Β βββ category.py
βΒ Β βΒ Β βΒ Β βββ question.py
βΒ Β βΒ Β βββ static
βΒ Β βΒ Β βΒ Β βββ swagger.json
βΒ Β βΒ Β βββ templates
βΒ Β βΒ Β βΒ Β βββ base.html
βΒ Β βΒ Β βΒ Β βββ developer.html
βΒ Β βΒ Β βΒ Β βββ home.html
βΒ Β βΒ Β βββ __init__.py
βΒ Β βΒ Β βββ views.py
βΒ Β βββ db
βΒ Β βΒ Β βββ init.sql
βΒ Β βββ instance
βΒ Β βΒ Β βββ dev_opentrivia.db
βΒ Β βββ migrations
βΒ Β βΒ Β βββ versions
βΒ Β βΒ Β βΒ Β βββ 798672a50ee1_.py
βΒ Β βΒ Β βββ README
βΒ Β βΒ Β βββ alembic.ini
βΒ Β βΒ Β βββ env.py
βΒ Β βΒ Β βββ script.py.mako
βΒ Β βββ tests
βΒ Β βΒ Β βββ __init__.py
βΒ Β βΒ Β βββ test_opentrivia.py
βΒ Β βββ config.py
βΒ Β βββ docker-compose.yml
βΒ Β βββ requirements.txt
βΒ Β βββ run.py
βββ CONTRIBUTING.md
βββ LICENSE
βββ README.md
βββ _config.yml
- Code Style
In order to maintain the code style consistency across entire project we use a code formatter. Therefore, we kindly suggest you to do the same whenever you push commits to this project.
The python code formatter we chose is called black. Black is a great tool and it can be installed quickly by running
pip install black
.
or
python3.6 -m pip install black
It requires Python 3.6.0+ to run.
- Usage
black {source_file_or_directory}
For more details and available options, please check the GitHub project.
- Close Issues
Close issues using keywords: how to ?
Available Views
- http://127.0.0.1:5000/ #Home Page
- http://127.0.0.1:5000/developer #Developer Page
- http://127.0.0.1:5000/swagger/ #Swagger UI
Available Endpoints
- Questions
-
GET api/v1/questions
(Get all Questions) -
GET api/v1/questions/<id>
(Get Question) -
POST api/v1/questions
(Create new Question) -
PUT api/v1/questions/<id>
(Update Question) -
DELETE api/v1/questions/<id>
(Delete Question)
-
- Answers
-
GET api/v1/answers/<id>
(Get Answer) -
POST api/v1/answers
(Create new Answer) -
PUT api/v1/answers/<id>
(Update Answer) -
DELETE api/v1/answers/<id
(Delete Answer)
-
- Categories
-
GET api/v1/categories
(Get all Categories) -
GET api/v1/categories/<id>
(Get Category) -
POST api/v1/categories
(Create new Category) -
PUT GET api/v1/categories/<id>
(Update Category) -
DELETE GET api/v1/categories/<id>
(Delete Category)
-
feel free to add more functionalities endpoint url structure: /api/v1/. . .