Created
November 23, 2022 17:39
-
-
Save carlosm27/649ccb13772614f21de26380c9c09c1e to your computer and use it in GitHub Desktop.
add fruit handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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