#Braiiin Logic Tier
a RESTful API for basic CRUD operations, for now
##Usage
Each service has a number of endpoints. For now, each "service" is quite simply another model.
RESTful API endpoints include the following:
/api/v1/[entity]
:GET
,POST
/api/v1/[entity]/[oid]
:PUT
,DELETE
All other endpoints will be formatted in one of two ways. Each method will have its own set of allowed HTTP methods:
/api/v1/[entity]/[endpoint]
/api/v1/[entity]/[oid]/[endpoint]
By default, services implement and expose the get
, fetch
, post
, put
, and
delete
endpoints.
##Developer Version
Installation
- Run
check.sh
to ensure bothpython3
andmongodb
are installed. - Run
install.sh
.
Installation is complete. If installation fails, see the long version below to debug step-by-step. Otherwise, jump down to "Testing".
- Make sure Python3, Pip, and Mongodb are installed.
- Create new virtaulenv named "env"
python3 -m venv env
. - Launch virtualenv
source env/bin/activate
. - Create mongodb datastore
mkdir env/db
. - Install requirements
pip3 install -r requirements.txt
.
Testing
To run tests, use py.test tests
.
Getting Started
- Launch server
source activate.sh
.
OR
- Launch datastore.
mongodb --dbpath env/db
. - Launch service.
python3 run.py
.
###Docstrings
All docstrings should use one of the following two formats:
Minimal
"""Basic docstring for the method or class"""
Detailed
"""
One-liner description
Information
-----------
Basic information about usage
Detail
------
Optional section with clarifications that may not be needed
Example
-------
Sample Usage
"""
###Separation of Purpose
Heed these guidelines when deciding where to put code.
- api.py : handling input/output for models, permissions by endpoint
- models.py : business logic
Here are logic-tier responsibilities:
- Convert all errors to human-readable messages.
##Production Deployment
Assumes a non-root, sudo-capable user, deploying to Ubuntu 14.04
- Update package index
sudo apt-get update
. - Upgrade everything
sudo apt-get upgrade
. - Install Apache2, MongoDB, Pip3, and Git
sudo apt-get install apache2 mongodb python3-pip git
. - Install Python3 WSGI
sudo apt-get install libapache2-mod-wsgi-py3
. - Make
python3
the default:sudo rm /usr/bin/python; sudo ln -s /usr/bin/python3 /usr/bin/python
. cd
to/var/www
.- Clone code
git clone https://.git
. - Disable multi-threading
sudo a2dismod mpm_event
. - Give Apache2 permission to run scripts
sudo a2enmod mpm_prefork cgi
. - Symlink configuration file for apache2
sudo ln -s /var/www/logic/logic.conf /etc/apache2/sites-available/logic.conf
. - Activate the site
sudo a2ensite logic
. - Deactivate the default site
sudo a2dissite 000-default
. cd logic
source install.sh
- Launch the datastore
sudo service mongodb start
. - Restart server
sudo service apache2 reload
.