Skip to content

Instantly share code, notes, and snippets.

@carlosm27
Created November 23, 2022 17:39
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/649ccb13772614f21de26380c9c09c1e to your computer and use it in GitHub Desktop.
Save carlosm27/649ccb13772614f21de26380c9c09c1e to your computer and use it in GitHub Desktop.
add fruit handler
@app.post("/fruit")
def add_fruit(request):
body = bytearray(request['body']).decode("utf-8")
fruit = json.loads(body)
new_id = fake_fruit_database[-1]['id'] + 1
fruit_dict = {"id":new_id, "fruit":fruit['fruit']}
fake_fruit_database.append(fruit_dict)
return {"status_code":201, "body":jsonify(fruit_dict), "type": "json"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment