A REST API created using the Flask micro-framework for the smartphone recommender android application "PhoneMate".
- Python - Version v3.5.2
Check if Python 3 is already installed.If Python 3 is not already installed, you can install it using the following command (For Debian systems):python --version
sudo apt-get install python3=3.5.2*
- Pip - Version v9.0.1
Check if pip is already installed.If not, install it using the follwing command (For Debian systems):pip --version
sudo apt-get install python3-pip
- virtualenv - Version v15.1.0
Check if virtualenv is already installed.If not, install it as follows:virtualenv --version
pip install virtualenv
- MongoDB - Version v3.4.13
Instructions to download it are available at the following link:
MongoDB Community Edition Server: https://docs.mongodb.com/manual/administration/install-community/
-
- Clone the project and put it in your home folder
This can be done using the Github Clone or download button or by using the following command:git clone https://github.com/vishvanatarajan/Phonemate-App-Backend.git
- Clone the project and put it in your home folder
-
- Open the project folder and create a virtual environment.
cd <your_project_directory> (Phonemate-App-Backend) virtualenv venv
- Open the project folder and create a virtual environment.
-
- Activate the virtual environment.
source venv/bin/activate
- Activate the virtual environment.
-
- Inside the project folder, create a folder called instance.
Now, create two files inside this folder:-
- init.py - To mark this folder as a Python package.
-
- config.py - A file that stores project sensitive information such as SECRET-KEY, API keys, etc.
- config.py - A file that stores project sensitive information such as SECRET-KEY, API keys, etc.
#Sample contents for instance/config.py DEBUG = True DATABASE_URI = "mongodb://localhost:27017/<database_name> DATABASE_NAME = <database_name> SECRET_KEY = "your-secret-key-needs-to-be-put-here" BCRYPT_LOG_ROUNDS = 14 #can be changed according to requirements, but this is ideal DEVELOPER_EMAIL = <give the developer email id> DEVELOPER_PASSWORD = <give the password against which this account will be validated>
-
- Inside the project folder, create a folder called instance.
-
- The SECRET_KEY can be generated with the following Python code:
import os os.urandom(24)
- The SECRET_KEY can be generated with the following Python code:
-
- Open the project folder in the terminal and install the required Python modules using the following command:
pip install -r requirements.txt
- Open the project folder in the terminal and install the required Python modules using the following command:
-
- Final Directory structure
Phonemate-App-Backend <project_folder> ├── instance │ ├── config.py │ └── __init__.py ├── phonemate │ ├── __init__.py │ ├── models │ │ ├── __init__.py │ │ ├── tokens.py │ │ └── users.py │ ├── static │ └── views.py ├── venv ├── requirements.txt └── run.py
- Final Directory structure
-
- Activate virtual environment:
In the project directory, open the terminal and type,
source venv/bin/activate
- Activate virtual environment:
In the project directory, open the terminal and type,
-
- Start your mongod server, if it is not already started.
To check status of mongod server in Ubuntu 16.04, type the following command in the terminal:In case the server is stopped, start it is using the following command:sudo systemctl status mongodb
sudo systemctl start mongodb
- Start your mongod server, if it is not already started.
-
- Run the project.
python run.py
- Run the project.
- Flask - A microframework for Python based on Werkzeug and Jinja 2.
- MongoDB - A Free and Open Source document based NoSQL database.
- MongoEngine - A Document-Object Mapper (think ORM, but for document databases) for working with MongoDB from Python.
- Flask-Bcrypt - A Flask extension that provides bcrypt hashing utilities to securely store password or other sensitive information in the database.
- Flask-CORS - A Flask extension for handling Cross Origin Resource Sharing (CORS), making cross-origin AJAX possible.
-
- If database errors are encountered, ensure that the DATABASE_URI in the [instance/config.py] is correct.
-
- Format of Authorization token to be sent is - "Bearer <JWT_encoded_token>".
If this format is not followed, JWT Signature errors will be encountered.
- Format of Authorization token to be sent is - "Bearer <JWT_encoded_token>".
-
- Whenever a HTTP request is sent, ensure that it always has a content-type: application/json.
- Whenever a HTTP request is sent, ensure that it always has a content-type: application/json.
By default, the app is set to run on http://localhost:5000
If you wish to change it to the IP of your machine, go to the run.py file and change its content as follows:
#run.py
from phonemate import app
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
The source code for the Phonemate android application can be found at the following link:
Link to the Phonemate android application