Skip to content

Commit

Permalink
added compatibility for JSON requests
Browse files Browse the repository at this point in the history
  • Loading branch information
root authored and root committed Jan 16, 2022
1 parent 850085a commit 26a638e
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions rest-light.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,14 @@ def check_access(input_args):
return (False, {'error': 'No API-Key provided'})

# function to reveive arguments from request
def parse_request(input_args, required_arguments):
logging.debug(input_args.to_dict(flat=False))
def parse_request(request, required_arguments):
input_args = None
if request.is_json:
input_args = request.get_json()
logging.debug(input_args)
else:
input_args = request.form
logging.debug(input_args.to_dict(flat=False))
valid, error = check_access(input_args)
if not valid:
return (valid, error)
Expand Down Expand Up @@ -168,7 +174,7 @@ def hello():
@app.route('/send', methods=['POST'])
def send():
request_valid, parsed_request = parse_request(
request.form, ['system_code', 'unit_code', 'state'])
request, ['system_code', 'unit_code', 'state'])
if not request_valid:
return parsed_request

Expand All @@ -181,7 +187,7 @@ def send():
@app.route('/codesend', methods=['POST'])
def codesend():
request_valid, parsed_request = parse_request(
request.form, ['decimalcode'])
request, ['decimalcode'])
if not request_valid:
return parsed_request

Expand Down

0 comments on commit 26a638e

Please sign in to comment.