The goal of this project is to use APIs to control and manage a web application using existing data models. A REST API is developed using Test Driven Development (TDD) with the following functionality:
- Displays questions:
- All questions and by category.
- Show the question, category, and difficulty.
- Show/hide the answer.
- Delete questions.
- Add questions and require that they include question and answer text.
- Search for questions based on a text query string.
- Play the quiz game, randomizing either all questions or within a specific category.
- The code adheres to the
PEP 8
style guide and follows common best practices. - RESTful principles are followed throughout the project, including appropriate naming of endpoints, use of HTTP methods GET, POST, and DELETE.
- Project handles common errors using the
@app.errorhandler
decorator function to format an API friendly JSON error response. Unittest
was used to test each endpoint for expected success and error behavior.
Tech stack includes:
React.js
for the website's frontend (provided by Udacity Team).Python3
andFlask
as server-side language and server-side framework.~PostgreSQL
as database of choice.SQLAlchemy ORM
as ORM library of choice.
-
Python 3.7 - Follow instructions to install the latest version of python for your platform in the python docs
-
Virtual Environment - Instructions for setting up a virtual environment for your platform can be found in the python docs
-
PostgreSQL - Make sure to have PostgreSQL installed, if it is not installed, follow instructions to download PostgreSQL in PostgreSQL Downloads
-
PIP Dependencies - Install the required dependencies by navigating to the
/backend
directory and running:
pip install -r requirements.txt
With Postgres running, create a trivia
database:
createdb trivia
Populate the database using the trivia.psql
. From the backend
folder in terminal run:
psql trivia < trivia.psql
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. By default, the Flask server runs on http://localhost:5000.
Project includes tests to ensure CRUD operations are successful and persist accurately in the database for GET, POST, PUT and DELETE HTTP requests.
To deploy the tests, run
dropdb trivia_test
createdb trivia_test
psql trivia_test < trivia.psql
python test_flaskr.py
Omit the dropdb
command the first time you run tests.
View the API README for detailed documentation of API endpoints which includes URL, request parameters and the response body.
tip: this frontend is designed to work with Flask-based Backend. so it will not load successfully if the backend is not working or not connected. Stand up the backend first, test using Postman or curl, update the endpoints in the frontend, and then the frontend should integrate smoothly.
-
Installing Node and NPM This project depends on Nodejs and Node Package Manager (NPM). Before continuing, you must download and install Node (the download includes NPM) from https://nodejs.com/en/download.
-
Installing project dependencies This project uses NPM to manage software dependencies. NPM Relies on the package.json file located in the
frontend
directory of this repository. After cloning, open your terminal and run:
npm install
tip:
npm i
is shorthand fornpm install
The frontend app was built using create-react-app. In order to run the app in development mode use npm start
. You can change the script in the package.json
file.
Open http://localhost:3000 to view it in the browser. The page will reload if you make edits.
npm start