Commit c2995c65 authored by Georg Wechslberger's avatar Georg Wechslberger

intial example

parents
from flask import Flask, request
from flask_cors import CORS
from json_tricks import dumps
from numpy import arange, reshape, sin
app = Flask(__name__)
# CORS is required to query this service from other webservers than this local python server
CORS(app)
# simple plot of a line
@app.route("/plot/test1", methods = ['POST'])
def plotdata():
# create a data structe of the form { x: [ ], y: [] } and send it back
data = {'x': arange(0, 10, 1, dtype=int), 'y': arange(2, 12, dtype=int)}
return dumps(data, primitives=True)
# plot of f(x;k) = sin(k*x) with paramter k being specified by the client
@app.route("/plot/test2", methods = ['POST'])
def plotdata2():
# parse the value of the parameter k from the request
options = request.get_json()
k = options['k']
# create a data structe of the form { x: [ x_i ], y: [sin(k*x_i)] } and send it back
data = {'x': arange(0, 6.2, 0.1, dtype=float), 'y': sin(k*arange(0, 6.2, 0.1, dtype=float))}
return dumps(data, primitives=True)
if __name__ == "__main__":
app.run()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment