Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Accept both json and raw data payloads for the state of the switch
@app.route("/Outlets/api/outlets/<int:groupNumber>/<int:buttonNumber>",methods=["PUT","POST"])
def update_outlet_state(groupNumber, buttonNumber):
state=None
if request.json is not None:
state=request.json.get("state")
else:
state=request.data
if (state is None):
abort(400)
if (state.lower() != 'on' and state.lower() != 'off'):
abort(400)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment