bookmark_borderINSTALL AND RUN FLASK(PYTHON) ON UBUNTU 19.04 on VpsServer

Flask is a lightweight WSGI web application framework. It is designed to make getting started quick and easy, with the ability to scale up to complex applications. It began as a simple wrapper around Werkzeug and Jinja and has become one of the most popular Python web application frameworks.


Step #0:
Signup (I appreciate if you use my referral link)
https://www.vpsserver.com/?affcode=21edd2c7bade
after your account becomes verified, create a Ubuntu 19.04 server.

Step #1:
Install python pip and flask by run:
$ sudo apt install python-pip
$ sudo apt install python3-pip
$ pip install -U Flask
$ pip3 install -U Flask

Step #2:
Add your project files on the server (ex. from GitHub using clone command)
in this tutorial let’s use a very simple flask app example that prints Hello, World! and save the app in (ex. /var/www/flask):

$ mkdir /var/www/flask
$ cd /var/www/flask
$ nano app.py
copy below code and paste it in app.py file using CTRL + SHIFT + V keys.

# app.py file

from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello, World!"

then press ( CTRL+ X )-> Y -> ENTER.


Step #3:
Run the server by run:
$ env FLASK_APP=app.py flask run -h xxx.xxx.xxx
change xxx.xxx.xxx to your server ip

output:

Serving Flask app "app.py"
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://xxx.xxx.xxx:5000/ (Press CTRL+C to quit)

bookmark_borderSimple System With GraphGL, Reactjs, PHP

simple system with GraphQL, Reactjs, PHP

Tools used: PHP v7.3^ , Symfony 4.4^ , React 16^ , VPS, SQL , Docker , overblog/GraphQLBundle

Preview:

as gif – video

note: this is my first time to use GraphQL & Reactjs

GraphiQL:

Example Query:

query {
buyer(id: 20){
id,
name,
authToken
},
products{
id,
name
},
buyers{
name
}
}

Example Mutation: 
Note: entered buyerID and productsIDs must be existed to create order!

mutation {
createOrder(buyerID: "20", productsIDs: ["26", "24"]){
id,
buyer{
name
},
products{
name,
id
}
}
}

Install & run:
  • $ git clone git@github.com:khaledalam/simple-system-with-graphql-react-php.git $ cd simple-system-with-graphql-react-php
  • Update DB info in .env file:DATABASE_URL=mysql://USERNAME:PASSWORD@127.0.0.1:PORT/DB_NAME
  • $ composer install # press (a) to accept all recipes $ yarn install $ php bin/console doctrine:database:create $ php bin/console doctrine:schema:update --force -n $ php bin/console doctrine:fixtures:load -n # add dummy buyers&products
  • $ php bin/console server:start
Assumptions:
  • I assume order can contain multi-products instead of a single product.
  • I assume we can use any ready jwt sandbox app (ex. example)
    • host jwt sandbox on any server
    • inject it throw register, login and retrieving buyer’s orders processes via HTTPexample: – curl -H “Authorization: jwt+[TOKEN]” http://jwt_server/getBuyerIdOfThisToken – compare returnedId with current buyer id – if equal then fetch all current buyer’s orders
  • I assume all current urls available only for admins
  • I assume validations are very basic annotation constraints
  • I assume we use symfony environment (ex. this docker-symfony)
  • I assume more improvements will be done (ex. decrease redundant codes, reducing repetition logic)
  • I assume using another toolkit that supports editing HTTP headers for graphql instead of playground(since I used symfony not laravel and no stable symfony bundle similar to mll-lab/laravel-graphql-playground)

GitHub: https://github.com/khaledalam/simple-system-with-graphql-react-php