Skip to content

A REST API created using the Flask micro-framework for the smartphone recommender android application "PhoneMate".

License

Notifications You must be signed in to change notification settings

vishvanatarajan/Phonemate-App-Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Phonemate-App-Backend

A REST API created using the Flask micro-framework for the smartphone recommender android application "PhoneMate".

Getting Started

Prerequisites

  • Python - Version v3.5.2
    Check if Python 3 is already installed.
    python --version
    If Python 3 is not already installed, you can install it using the following command (For Debian systems):
    sudo apt-get install python3=3.5.2*

  • Pip - Version v9.0.1
    Check if pip is already installed.
    pip --version
    If not, install it using the follwing command (For Debian systems):
    sudo apt-get install python3-pip

  • virtualenv - Version v15.1.0
    Check if virtualenv is already installed.
    virtualenv --version
    If not, install it as follows:
    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/

Installing

    1. 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
    1. Open the project folder and create a virtual environment.
      cd <your_project_directory> (Phonemate-App-Backend)
      virtualenv venv
    1. Activate the virtual environment.
      source venv/bin/activate
    1. Inside the project folder, create a folder called instance.
      Now, create two files inside this folder:
        1. init.py - To mark this folder as a Python package.
        1. 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>
    1. The SECRET_KEY can be generated with the following Python code:
      import os
      os.urandom(24)
    1. Open the project folder in the terminal and install the required Python modules using the following command:
      pip install -r requirements.txt
    1. 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

Running the Server

    1. Activate virtual environment: In the project directory, open the terminal and type,
      source venv/bin/activate
    1. 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:
      sudo systemctl status mongodb
      In case the server is stopped, start it is using the following command:
      sudo systemctl start mongodb
    1. Run the project.
      python run.py

Built With

  • 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.

Debugging Tips

    1. If database errors are encountered, ensure that the DATABASE_URI in the [instance/config.py] is correct.
    1. Format of Authorization token to be sent is - "Bearer <JWT_encoded_token>".
      If this format is not followed, JWT Signature errors will be encountered.
    1. Whenever a HTTP request is sent, ensure that it always has a content-type: application/json.

Note

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)

Link to Phonemate android application

The source code for the Phonemate android application can be found at the following link:
Link to the Phonemate android application

About

A REST API created using the Flask micro-framework for the smartphone recommender android application "PhoneMate".

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published