Skip to content

Instantly share code, notes, and snippets.

@xiaopeng163
Created December 4, 2018 18:02
Show Gist options
  • Save xiaopeng163/c54c7e66a75cb830d6c63e505fa07083 to your computer and use it in GitHub Desktop.
Save xiaopeng163/c54c7e66a75cb830d6c63e505fa07083 to your computer and use it in GitHub Desktop.
from flask import Flask, jsonify
import random
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
@app.route('/temperature')
def get_temp():
data = {
'data': random.uniform(10, 15)
}
return jsonify(data)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080)
@xiaopeng163
Copy link
Author

$ pip install flask
python app.py
 * Serving Flask app "app" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)

you can get a random temperature value from http://127.0.0.1:8080/temperature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment