Forums

How to execute simple Flask Service ?

This is my code:

#!flask/bin/python
from flask import Flask
app = Flask(__name__)
from flask import Flask
from flask import request
app = Flask(__name__)
@app.route('/substraction', methods=['POST'])
def post():
    content = request.get_json();    
    val1 = content['val1'];
    val2 = content['val2'];
    sumValue = int(val1) - int(val2);
    print(sumValue);
    return 'sum'+str(sumValue);

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=6000)

This is the output on my console-

14:57 ~/DeployWebServices $ python GetSubstractionExample.py                                                                                        
 * Running on http://0.0.0.0:6000/ (Press CTRL+C to quit)

*** NOTE: THE CHANGE IN PORT *******

How to test the service, please help ?

Thanks, Rahul V. vaish.rahul4810@gmail.com

[edit by admin: formatting]

On PythonAnywhere you don't need to run the script from the console -- you set it up on the "Web" page instead. We have a tutorial on writing a Flask site; if you follow the first few steps then everything should become clear.