This repository contains tutorial to deploy any of your existing research into easily usable web services.
This is simple python program to perform addition of two numbers.
from __future__ import print_function
# to make sure print() on both python 2 and python 3 properly
#declare two numbers
number1 = 5
number2 = 10
#perform addition of two numbers
answer = number1 + number2
#print answer
print("Answer is:"+str(answer))
In this code we will create simple webserver using Flask in python. Page will simpaly display "Hello World as output"
# For creating simple web page we need to import flask
from flask import Flask
#assign name to our flask application
#You can either use app's default name
app = Flask(__name__)
#or assign name yourself
#app = Flask("simple_hello_application")
# define path on which application will respond and also create function to handle request
@app.route('/')
def index():
#simply print "hello world"
return 'Hello world'
if __name__ == '__main__':
#if it is main program, run flask server on localhost with 9090 port number
app.run(debug=True, host='0.0.0.0',port=9090)
In this code we add multiple page to practical 2.
For doing that we need to add following code to practical 2:
@app.route('/sttp')
def sttp():
return 'Hello Python developers'
In this practical we will handle GET, POST and JSON request using flask.
We can handle get request either via query string or we can fetch values directly from url.
For this we can use <>.
@app.route('/calculator/<a>/<b>')
def success(a,b):
ans = int(a)+int(b)
return 'answer is %s' % ans
Syntax: request.args.get('parameter_name')
@app.route('/calculator2', methods=['GET'])
def calc():
if request.method == 'GET':
a = request.args.get('a')
b = request.args.get('b')
c=int(a)+int(b)
return str(c)
Syntax: request.form['parameter_name']
@app.route('/calculator2', methods=['POST'])
def calc():
if request.method == 'POST':
a = request.form['a']
b = request.form['b']
c=int(a)+int(b)
return str(c)
Syntax: request.get_json(silent=True, force=True)
silent for no warning
force for ignoring header type
@app.route('/jsondemo', methods=['POST', 'GET'])
def jsondemo():
content = request.get_json(silent=True, force=True)
return str( int(content['a']) + int(content['b']) )
wget https://github.com/rancher/install-docker/blob/master/17.03.2.sh
sh rancherdockerinstall.sh
sudo docker ps -a
sudo docker images
sudo docker rmi IMAGE-ID
sudo docker run --name sttp shahparth123/apache:0.4
With more option
sudo docker run -d --restart=unless-stopped -it --name lab4 -v /home/parthpunita/demo/:/var/www/html -p 80:80 -p 443:443 -p 2022:22 shahparth123/apache:0.4
sudo docker commit -a "Parth Shah" -m "demo server" lab5 shahparth123/apache:latest
docker rm CONTAINER-ID/name