Skip to content

Instantly share code, notes, and snippets.

@carlosm27
Created November 23, 2022 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosm27/0d08e8a6c22327359eaf9a075fd8d778 to your computer and use it in GitHub Desktop.
Save carlosm27/0d08e8a6c22327359eaf9a075fd8d778 to your computer and use it in GitHub Desktop.
update_fruit handler
@app.put("/fruit/:id")
def update_fruit(request):
id = request["params"]["id"]
body = bytearray(request['body']).decode("utf-8")
fruit = json.loads(body)
fruit_id = int(id)
fruit_dict = get_item(fruit_id,fake_fruit_database)
if fruit_dict == {}:
return {"status_code":404,"body":"Fruit not Found", "type": "text"}
else:
fruit_dict['fruit'] = fruit['fruit']
return jsonify(fruit)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment