API Setup - PARC-projects/video-query-home GitHub Wiki

Video Query API was created using the Django Rest Framework project. We strive to stay on the edge build of the Django platform. Accordingly, this project requires Python 3.

Dependencies

Start by installing the following packages.

pip install django
pip install djangorestframework
pip install django-filter
pip install django-cors-headers
pip install psycopg2
pip install coreapi
pip install Pillow
pip install markdown       # Markdown support for the browsable API.

Additional required packages, which will be flagged if missing when attempting to build the API:

Package Version
Django 2.2.4
Markdown 3.1.1
Pillow 6.1.0
django-cors-headers 3.0.2
django-filter 2.2.0
djangorestframework 3.10.2
psycopg2 2.8.3
pytz 2019.2
coreapi 2.3.3
pygments 2.2.0

Environment Variables

A number of environment variable are required for both dev and production.

  • API_DEBUG
    • dev: Set to False.
    • production: Set to True.
  • API_SECRET_KEY
    • dev: Any random number will do.
    • production: Use a secret key that is unique to the deployment.
  • API_DB_HOST
    • dev: Set to localhost
    • production: Set to your deployment domain.
  • API_DB_PORT
    • dev and production: Set to your instance of PostgreSQL deployment port. For PostgreSQL, this is typically 5432.
  • ALLOWED_HOST
    • dev = Can be omitted.
  • API_CORS_ORIGIN_WHITELIST
    • dev = Can be omitted.
    • production = Set to any domain that is accessing the API other than the API's deployed domain. For example, a deployment instance of the web client project would require its accompanying domain to be listed here.
  • API_DB_NAME
    • set to the name of the PostgreSQL database set up for this API
  • API_DB_USER
    • set to the PostgreSQL user name with access to the above database
  • API_DB_PASS
    • password for the above PostgreSQL user

One way to set these is to execute

bash secrets.sh in Linux or
source secrets.sh in MacOS,

using a secrets.sh file in your local video-query-api main directory. Here is an example of a secrets.sh file used for development:

secrets.sh:

#!/usr/bin/env bash
# on Mac, execute 'source secrets.sh' from command line
export API_DEBUG='False'
export API_SECRET_KEY='983471509835445'
export API_DB_NAME='Video-Query'
export API_DB_USER='username'
export API_DB_PASS='some_clever_password'
export API_DB_HOST='localhost'
export API_DB_PORT='5432'