mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-21 23:55:13 -05:00
Reverse API: added server example
This commit is contained in:
parent
663684dd9d
commit
b6ec5e24a6
1
.gitignore
vendored
1
.gitignore
vendored
@ -21,3 +21,4 @@ debian/sdrangel.debhelper.log
|
||||
debian/debhelper-build-stamp
|
||||
obj-x86_64-linux-gnu/*
|
||||
**/venv/
|
||||
*.pyc
|
||||
|
33
swagger/sdrangel/examples/server.py
Normal file
33
swagger/sdrangel/examples/server.py
Normal file
@ -0,0 +1,33 @@
|
||||
from flask import Flask
|
||||
from flask import request, jsonify
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
@app.route('/sdrangel')
|
||||
def hello_sdrangel():
|
||||
return 'Hello, SDRangel!'
|
||||
|
||||
|
||||
@app.route('/sdrangel/deviceset/<int:deviceset_index>/device/run', methods=['GET', 'POST', 'DELETE'])
|
||||
def device_run(deviceset_index):
|
||||
if request.method == 'POST':
|
||||
print("Start device %d" % deviceset_index)
|
||||
reply = { "state": "idle" }
|
||||
return jsonify(reply)
|
||||
elif request.method == 'DELETE':
|
||||
print("Stop device %d" % deviceset_index)
|
||||
reply = { "state": "running" }
|
||||
return jsonify(reply)
|
||||
elif request.method == 'GET':
|
||||
return "RUN device %d" % deviceset_index
|
||||
|
||||
|
||||
@app.route('/sdrangel/deviceset/<int:deviceset_index>/device/settings', methods=['GET', 'PATCH', 'PUT'])
|
||||
def device_settings(deviceset_index):
|
||||
content = request.get_json(silent=True)
|
||||
if request.method == 'PATCH':
|
||||
return jsonify(content)
|
||||
if request.method == 'PUT':
|
||||
return jsonify(content)
|
||||
if request.method == 'GET':
|
||||
return 'GET settings'
|
Loading…
Reference in New Issue
Block a user