-
Notifications
You must be signed in to change notification settings - Fork 0
API
Requires Python 3.7 or above
-
Run
sudo apt-get install libapache2-mod-wsgi python-dev -
Create a directory in
/var/wwwfor the API, and name it something likenexusapi -
Put
api.pyandauth.csvin that folder, and add API keys to that file. -
Create a file called
api.wsgiand put the following into itimport sys sys.path.insert(0, '/var/www/yourdir') from api import app as application
-
Add the following to your Apache config
WSGIDaemonProcess api user=www-data group=www-data threads=5 WSGIScriptAlias "/api" "/var/www/yourdir/api.wsgi" <Directory /var/www/yourdir> WSGIProcessGroup progpilot WSGIApplicationGroup %{GLOBAL} Require all granted </Directory> -
Restart Apache, and your API should be present at http://www.example.com/api
- If you'd like to have the API accessible from another path, change
WSGIScriptAlias "/api"toWSGIScriptAlias "/yourpath", meaning you should be able to access the API from http://www.example.com/yourpath
- If you'd like to have the API accessible from another path, change
The main API has its own error logging in combination with what Apache will log for you. Any failures or breakages will be logged in a file in the same directory as api.py (herein referred to as the script) called error.log.
There are numerous helper functions in the script with are used in a lot of functions used for requests. Each of these has a fairly self explanatory name, or is fairly explanatory. There are a couple of notable functions:
- error_frame
- error_frame will generate JSON for a response based on an error message, a HTTP code and a