Skip to content

Latest commit

 

History

History
 
 

backend

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Backend - Trivia API

Setting up the Backend

Install Dependencies

  1. Python 3.7 - Follow instructions to install the latest version of python for your platform in the python docs

  2. Virtual Environment - We recommend working within a virtual environment whenever using Python for projects. This keeps your dependencies for each project separate and organized. Instructions for setting up a virual environment for your platform can be found in the python docs

  3. PIP Dependencies - Once your virtual environment is setup and running, install the required dependencies by navigating to the /backend directory and running:

pip install -r requirements.txt

Key Pip Dependencies

  • Flask is a lightweight backend microservices framework. Flask is required to handle requests and responses.

  • SQLAlchemy is the Python SQL toolkit and ORM we'll use to handle the lightweight SQL database. You'll primarily work in app.pyand can reference models.py.

  • Flask-CORS is the extension we'll use to handle cross-origin requests from our frontend server.

Set up the Database

With Postgres running, create a trivia database:

For Linux

createdb trivia

For windows

cd into backend dir
psql trivia postgres
\i trivia.psql

Populate the database using the trivia.psql file provided. From the backend folder in terminal run:

For Linux

psql trivia < trivia.psql

For windows

cd into backend dir
psql trivia postgres
\i trivia.psql

Set up the Server/Flask

For no windows OS

From within the ./src directory first ensure you are working using your created virtual environment.

To run the server, execute:

flask run --reload

The --reload flag will detect file changes and restart the server automatically.

For windows OS

From within the ./src directory first ensure you are working using your created virtual environment. enter the following command in order.

$env:FLASK_APP = "flaskr"
$env:FLASK_ENV: "development"
flask run

Testing

To deploy the tests, run

Linux

dropdb trivia_test
createdb trivia_test
psql trivia_test < trivia.psql
python test_flaskr.py

Windows

(form within the backend dir)
psql postgres postgres
drop database trivia_test
create database trivia_test
\c trivia_test
\i trivia.psql
python test_flaskr.py

API DOCUMENTATION

Please check here for the API documentation and test queries

🐱‍👤🐱‍👤🐱‍👤🐱‍👤🐱‍👤🐱‍👤🐱‍👤🐱‍👤🐱‍👤🐱‍👤🐱‍👤